Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stoopkid> in swipl are there best practices regarding the use of atoms vs. double-quoted strings?
- 1:40 PM for representation of text data
- 1:40 PM let's say.. not like paragraphs of text but just like "My Column Header" or some such
- 2:08 PM → gareppa joined (~gareppa@unaffiliated/gareppa)
- 2:09 PM
- <dmiles> ... atoms are supposed to be used when the strings mean something important to your program
- 2:09 PM "My Column Header" means more to the user
- 2:11 PM 'Column Header ID 666' though would be an atom
- 2:12 PM teh atom in that case will use memory in general
- 2:12 PM as it becomes a global enum
- 2:13 PM vs the string is always allocated as least globally as poissble
- ...
- <stoopkid> dmiles: hrmm... https://www.swi-prolog.org/pldoc/man?section=ext-dquotes-motivation
- 2:24 PM "Representing text using atoms is often considered inadequate for several reasons: 1) It hides the conceptual difference between text and program symbols. Where content of text often matters because it is used in I/O, program symbols are merely identifiers that match with the same symbol elsewhere. Program symbols can often be consistently replaced, for example to obfuscate or compact a program. "
- 2:25 PM from this i'm gathering that if you want the data to represent that specific piece of text, as opposed to some arbitrary identifier that could hypothetically be replaced w/ a different identifier, then it should be a string
- 2:27 PM
- <dmiles> ... identifiers are intended to be unique ID?
- 2:28 PM (if so, then i would make them go into the global table.. like i did with 'Column Header ID 666')
- 2:29 PM → freeman42x joined (~freeman42@2a02:8084:e80:9580:b5c1:77d1:8cdc:2d87)
- 2:29 PM
- <stoopkid> well, let's say you're actually writing that column to output w/ the header included, do we want the header to literally say exactly "Column Header ID 666" or do we not care what it says?
- 2:30 PM
- <dmiles> ... "Program symbols can often be consistently replaced," the compiled program would not need the text of the information
- 2:30 PM only that it wasn tthe same as 'Column Header ID 667'
- 2:31 PM those atoms can be replaced by 'foo1' and 'foo2' and hte program will still operate
- 2:31 PM if i want to out those.. tha tis a differnt story
- 2:32 PM to output those, i might still use an atom in this case because i can output atoms.. i just dont want too arbitaryly rename them
- 2:33 PM but *only* wouild keep it as an atom if my program really understood them
- 2:33 PM not "but" .. "and" there
- 2:34 PM
- <stoopkid> so how would you indicate to an obfuscator which atoms can be substituted and which ones represent exact text and thus can't be substituted?
- 2:35 PM
- <dmiles> ... i have a private way i do that which i am suire other programers would find annyying i actual make my atoms appear like '"Dont obfusicate me"'
- 2:35 PM '"text"'
- 2:35 PM
- <stoopkid> ic
- 2:36 PM
- <dmiles> ... it also makes me remember i am outputing it
- 2:36 PM and since it is aukward to type uit reminds me of the debt created
- 2:37 PM so when to use strings? When i am receivned new data from the outside world.. or creating it programmatically
- 2:38 PM when trying to protected the limited resources of the global dictionary
- 2:39 PM " They are stored in a shared table. Volatile strings represented as atoms come at a significant price due to the required cooperation between threads for creating atoms. Reclaiming temporary atoms using Atom garbage collection is a costly process that requires significant synchronisation."
- 2:40 PM
- <stoopkid> so do you have some custom code or w/e to manipulate atoms that contain double-quotes like that?
- 2:40 PM
- <dmiles> ... yes.. that code removes the quotes from printing
- 2:41 PM
- <stoopkid> well, but also for like append, substring, etc..
- 2:41 PM sorry, concat*, substring, etc..
- 2:41 PM seems you'd have to wrap every string manipulation predicate in something that deals w/ the double-quotes
- 2:41 PM
- <dmiles> ... if i am performing thos operates than i should be using a string datatype
- 2:42 PM
- <stoopkid> hrm
- 2:42 PM
- <dmiles> ... but i do that that code .. i just promise to never use it :P
- 2:42 PM
- <stoopkid> idk, swipl does provide atomic_list_concat and such after all
- 2:42 PM
- <dmiles> ... since it has to dewrap.. operate.. rewrap
- 2:43 PM atomic_list_concat btw operates on strings
- 2:43 PM ?- atomic_list_concat(List,' ',"I was a string").
- 2:43 PM ?- atomic_list_concat(List,' ',"I was a string")
- 2:43 PM
- <yesbot> anonymous 'List'=['I',was,a,string]
- 2:44 PM
- <stoopkid> that's a list of atoms though right?
- 2:44 PM
- <dmiles> ... yes
- 2:44 PM ?- atomic_list_concat(['I',was,a,string],' ',NowIHohhingRam)
- 2:44 PM
- <yesbot> anonymous 'NowIHohhingRam'='I was a string'
- 2:45 PM
- <stoopkid> so swipl seems to assume that users would indeed be doing these kind of string manipulations directly on atoms
- 2:45 PM
- <dmiles> ... ?- atomic_string_concat(['I','have','already','been','GCed'],' ',X)
- 2:45 PM
- <yesbot> anonymous procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
- 2:45 PM 2 + 2 = 5.
- 2:46 PM → pie_ joined (~pie_@unaffiliated/pie-/x-0787662)
- 2:47 PM
- <stoopkid> atom_concat, atomic_list_concat, sub_atom, sub_atom_icasechk, ...
- 2:47 PM
- <dmiles> ... well now it is frowned upon.. but lots of code still does that
- 2:47 PM
- <stoopkid> ic
- 2:49 PM
- <dmiles> ... sub_atom_* is mostly for when you are needidng to created and decompose new global identifiers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement