sym and context

Started by William James, June 29, 2006, 11:11:58 AM

Previous topic - Next topic

William James

newLISP v.8.9.0 on Win32 MinGW, execute 'newlisp -h' for more info.

> (while (read-line)(dolist (word (parse (current-line)))(sym word 'HT)))
It was a dark
and stormy night.
^Z
HT:night.
> (context HT) (symbols)
HT
(It a HT:and dark night. stormy was)
HT>

Why is it HT:and instead of and?

cormullion

#1
Isn't it recommended somewhere to preface words in contexts with "_" to avoid conflicting with built-in functions such as and?


(sym (string "_" word) 'HT)

giving HT's symbols as:


_It
_a
_and
_dark
_night
_stormy
_was
[/i]

Lutz

#2
Because of (sym word 'HT) all words where created in namespace HT. When displayed, all reserved global words (like the built-in function 'and') are prefixed with HT to indicate that the local HT version is meant and not the global version.



Like Courmulllion suggests, I would prefix all words with an underscore, like (sym (append "_" word) 'HT)



Lutz

William James

#3
Thanks.  Instead of prefixing an underscore, I think that I may prefer to make sure that I get the symbol list from within another context.
> (symbols HT)
(HT:It HT:a HT:and HT:dark HT:night. HT:stormy HT:was)

So each and every symbol will start with "HT:" and I'll simply trim that from the beginning of the word instead of trimming "_".

Lutz

#4
Using the 'name' function you can get the name back as a string without the prefix:



(map name (symbols HT))

=> ("It" "a" "and" "dark" "night." "stormy" "was")


Lutz

William James

#5
Perfect.  I had forgotten about that.