sym and context

For the Compleat Fan
Locked
William James
Posts: 58
Joined: Sat Jun 10, 2006 5:34 am

sym and context

Post by William James »

Code: Select all

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
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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

Code: Select all

(sym (string "_" word) 'HT)
giving HT's symbols as:

Code: Select all

_It
_a
_and
_dark
_night
_stormy
_was
[/i]

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 58
Joined: Sat Jun 10, 2006 5:34 am

Post by William James »

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.

Code: Select all

> (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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Code: Select all

(map name (symbols HT))

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

William James
Posts: 58
Joined: Sat Jun 10, 2006 5:34 am

Post by William James »

Perfect. I had forgotten about that.

Locked