[George] TypCreate issues

Freeform discussion about anything related to modding Transcendence.
Post Reply
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

In the old 1.2 alpha I was able to use 'foo identifiers in Uncharted but when pixel fixed Uncharted it was pointed out that strings work (as in "foo").

Why would 'foo identifiers fail when string identifiers work? Is there an inherent difference?
Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Could you include the code and instructions for me to reproduce the problem? Thanks!
User avatar
pixelfck
Militia Captain
Militia Captain
Posts: 571
Joined: Tue Aug 11, 2009 8:47 pm
Location: Travelling around in Europe

I think I can explain this

The problem was not an identifier in the form of:

Code: Select all

'foo
'Charon
but instead an identifier in the form of:

Code: Select all

'foo'bar
'Jiang's Star
'Astaf'ev
which needed to be rewritten as a string:

Code: Select all

"foo'bar"
"Jiang's Star"
"Astaf'ev"
Hope this helps,
Pixelfck
Image
Download the Black Market Expansion from Xelerus.de today!
My other mods at xelerus.de
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Thanks--that explains it.

This is due to Lisp syntax (or at least my variant of it). The short answer is that the single-quote character is a special character in Lisp and cannot be used as part of an identifier. It can be used in a literal string, which means you need to put double-quotes around the whole string. This is the same as the colon character, parentheses, braces, etc.

Here is the longer answer:

One of the fundamental concepts in Lisp is the evaluation of an expression. Try the following expression (you can test this with TransData /run):

Code: Select all

(print (add 1 1))
We intuitively expect this to output "2". But why? Why doesn't this output "(add 1 1)"? The reason is that arguments to functions are (generally) evaluated before they are passed in. That is, we evaluate the result of (add 1 1) and pass the result of the evaluation as an argument to print. I think we all get this.

Similarly:

Code: Select all

(print foo)
Obviously, foo must be evaluated before we pass it into print. What does foo evaluate to? If foo is a variable, it evaluates to whatever the variable is set to. If foo is undefined, we get an error. But regardless, the rule is that we have to evaluate it.

Now consider:

Code: Select all

(print "foo")
We now have a quoted string as an argument, but the rules don't change: we have to evaluate it. What does a quoted string evaluate to? It evaluates to itself, so we end up printing the string "foo" (without the quotes). The double-quotes are a special syntax to create a literal string, which evaluates to itself.

But what if we DON'T want to evaluate something? Try this:

Code: Select all

(print (quote (add 1 1)))
The result is a list: (add 1 1). What happened? The quote function is a special instruction that does NOT evaluate its arguments. Instead, it just returns the unevaluated value. In this case, the unevaluated value is a list with three elements: add, 1, and 1.

This works with identifiers too:

Code: Select all

(print (quote foo))
The result is foo.

You might have guessed that the single-quote syntax is just a short-cut for the above:

Code: Select all

(print 'foo) is equivalent to (print (quote foo))
In other words, the single-quote syntax is a way to tell Lisp NOT to evaluate an expression. This also works with lists:

Code: Select all

(print '(add 1 1)) is equivalent to (print (quote (add 1 1)))
Note that there is a clear difference between '(add 1 1) and "(add 1 1)". The former is a list consisting of three elements; the latter is a single string.

Perhaps now you can see the problem with using single-quotes inside identifiers. Since the single-quote is a special character that means "do not evaluate this" we can't use it inside of identifiers:

Code: Select all

(print 'foo'bar) -> ERROR
Since single-quotes are special characters, we need to put them in double-quotes:

Code: Select all

(print "foo'bar")
As you can see there is a big difference between a single-quote and a double-quoted literal string. The single-quote character tells Lisp to NOT evaluate an expression. The double-quote character is used to form a literal string (which always evaluates to itself). Hope that helps!
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

George wrote:As you can see there is a big difference between a single-quote and a double-quoted literal string. The single-quote character tells Lisp to NOT evaluate an expression. The double-quote character is used to form a literal string (which always evaluates to itself). Hope that helps!
That helps so much! I always thought they were the same thing (a string) but didn't realize that single quote was just an unevaluated expression.

Honestly though I have to thank you on a deeper level. All of your explanations are helpful and clear, and have enabled me to learn a lot about TLISP and computer science in general. Ever since I've entered uni I've dropped by a few classes using Matlab/Octave and I feel more equipped to learn it than my peers. I've learned so much that just couldn't be taught in the classroom, and gained a lot of experience from modding about what it truly means to start and finish a project (hint: it never ends ;) ). This is all thanks to Transcendence, modding, TLISP, and you, George.
Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
george moromisato
Developer
Developer
Posts: 2998
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

RPC wrote:
George wrote:Honestly though I have to thank you on a deeper level. All of your explanations are helpful and clear, and have enabled me to learn a lot about TLISP and computer science in general. Ever since I've entered uni I've dropped by a few classes using Matlab/Octave and I feel more equipped to learn it than my peers. I've learned so much that just couldn't be taught in the classroom, and gained a lot of experience from modding about what it truly means to start and finish a project (hint: it never ends ;) ). This is all thanks to Transcendence, modding, TLISP, and you, George.
I'm really happy to hear this! I got my first job out of school by showing my prospective employer a game I'd written (Anacreon), so I'm a huge proponent of computer games as learning tools and experience-builders. One of my tenets at Kronosaur Productions is that all our games should have a modding component, for exactly this reason.
User avatar
Ttech
Fleet Admiral
Fleet Admiral
Posts: 2767
Joined: Tue Nov 06, 2007 12:03 am
Location: Traveling in the TARDIS
Contact:

george moromisato wrote:
RPC wrote:
George wrote:Honestly though I have to thank you on a deeper level. All of your explanations are helpful and clear, and have enabled me to learn a lot about TLISP and computer science in general. Ever since I've entered uni I've dropped by a few classes using Matlab/Octave and I feel more equipped to learn it than my peers. I've learned so much that just couldn't be taught in the classroom, and gained a lot of experience from modding about what it truly means to start and finish a project (hint: it never ends ;) ). This is all thanks to Transcendence, modding, TLISP, and you, George.
I'm really happy to hear this! I got my first job out of school by showing my prospective employer a game I'd written (Anacreon), so I'm a huge proponent of computer games as learning tools and experience-builders. One of my tenets at Kronosaur Productions is that all our games should have a modding component, for exactly this reason.
Some day we might actually be able to finish that lesson / book :D
Image
Image
Post Reply