Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. stoopkid> in swipl are there best practices regarding the use of atoms vs. double-quoted strings?
  2. 1:40 PM for representation of text data
  3. 1:40 PM let's say.. not like paragraphs of text but just like "My Column Header" or some such
  4. 2:08 PM → gareppa joined (~gareppa@unaffiliated/gareppa)
  5. 2:09 PM
  6. <dmiles> ... atoms are supposed to be used when the strings mean something important to your program
  7. 2:09 PM "My Column Header" means more to the user
  8. 2:11 PM 'Column Header ID 666' though would be an atom
  9. 2:12 PM teh atom in that case will use memory in general
  10. 2:12 PM as it becomes a global enum
  11. 2:13 PM vs the string is always allocated as least globally as poissble
  12.  
  13. ...
  14.  
  15. <stoopkid> dmiles: hrmm... https://www.swi-prolog.org/pldoc/man?section=ext-dquotes-motivation
  16. 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. "
  17. 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
  18. 2:27 PM
  19. <dmiles> ... identifiers are intended to be unique ID?
  20. 2:28 PM (if so, then i would make them go into the global table.. like i did with 'Column Header ID 666')
  21. 2:29 PM → freeman42x joined (~freeman42@2a02:8084:e80:9580:b5c1:77d1:8cdc:2d87)
  22. 2:29 PM
  23. <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?
  24. 2:30 PM
  25. <dmiles> ... "Program symbols can often be consistently replaced," the compiled program would not need the text of the information
  26. 2:30 PM only that it wasn tthe same as 'Column Header ID 667'
  27. 2:31 PM those atoms can be replaced by 'foo1' and 'foo2' and hte program will still operate
  28. 2:31 PM if i want to out those.. tha tis a differnt story
  29. 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
  30. 2:33 PM but *only* wouild keep it as an atom if my program really understood them
  31. 2:33 PM not "but" .. "and" there
  32. 2:34 PM
  33. <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?
  34. 2:35 PM
  35. <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"'
  36. 2:35 PM '"text"'
  37. 2:35 PM
  38. <stoopkid> ic
  39. 2:36 PM
  40. <dmiles> ... it also makes me remember i am outputing it
  41. 2:36 PM and since it is aukward to type uit reminds me of the debt created
  42. 2:37 PM so when to use strings? When i am receivned new data from the outside world.. or creating it programmatically
  43. 2:38 PM when trying to protected the limited resources of the global dictionary
  44. 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."
  45. 2:40 PM
  46. <stoopkid> so do you have some custom code or w/e to manipulate atoms that contain double-quotes like that?
  47. 2:40 PM
  48. <dmiles> ... yes.. that code removes the quotes from printing
  49. 2:41 PM
  50. <stoopkid> well, but also for like append, substring, etc..
  51. 2:41 PM sorry, concat*, substring, etc..
  52. 2:41 PM seems you'd have to wrap every string manipulation predicate in something that deals w/ the double-quotes
  53. 2:41 PM
  54. <dmiles> ... if i am performing thos operates than i should be using a string datatype
  55. 2:42 PM
  56. <stoopkid> hrm
  57. 2:42 PM
  58. <dmiles> ... but i do that that code .. i just promise to never use it :P
  59. 2:42 PM
  60. <stoopkid> idk, swipl does provide atomic_list_concat and such after all
  61. 2:42 PM
  62. <dmiles> ... since it has to dewrap.. operate.. rewrap
  63. 2:43 PM atomic_list_concat btw operates on strings
  64. 2:43 PM ?- atomic_list_concat(List,' ',"I was a string").
  65. 2:43 PM ?- atomic_list_concat(List,' ',"I was a string")
  66. 2:43 PM
  67. <yesbot> anonymous 'List'=['I',was,a,string]
  68. 2:44 PM
  69. <stoopkid> that's a list of atoms though right?
  70. 2:44 PM
  71. <dmiles> ... yes
  72. 2:44 PM ?- atomic_list_concat(['I',was,a,string],' ',NowIHohhingRam)
  73. 2:44 PM
  74. <yesbot> anonymous 'NowIHohhingRam'='I was a string'
  75. 2:45 PM
  76. <stoopkid> so swipl seems to assume that users would indeed be doing these kind of string manipulations directly on atoms
  77. 2:45 PM
  78. <dmiles> ... ?- atomic_string_concat(['I','have','already','been','GCed'],' ',X)
  79. 2:45 PM
  80. <yesbot> anonymous procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  81. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  82. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  83. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  84. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  85. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  86. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  87. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  88. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  89. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  90. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  91. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  92. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  93. 2:45 PM procedure `prolog_eval:atomic_string_concat(A,B,C)' does not exist
  94. 2:45 PM 2 + 2 = 5.
  95. 2:46 PM → pie_ joined (~pie_@unaffiliated/pie-/x-0787662)
  96. 2:47 PM
  97. <stoopkid> atom_concat, atomic_list_concat, sub_atom, sub_atom_icasechk, ...
  98. 2:47 PM
  99. <dmiles> ... well now it is frowned upon.. but lots of code still does that
  100. 2:47 PM
  101. <stoopkid> ic
  102. 2:49 PM
  103. <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