curly strings and symbols

Q&A's, tips, howto's
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

curly strings and symbols

Post by HPW »

Is this right that curly bracket string and symbols are not allowed to direkt follow each other?

Code: Select all

> (setq Test 10)
10
> (setq Test1 (string {Bla}Test{Bla1}))
Blanil
> (setq Test1 (string {Bla} Test {Bla1}))
Bla10Bla1
Or Bug?
Hans-Peter

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Re: curly strings and symbols

Post by xytroxon »

No...

Without " ' ( ) : , or the space character before { in Test{Bla1}

It is parsed as a legal variable per rule 3.
1. Syntax of symbol variables and numbers

Source code in newLISP is parsed according to the rules outlined here. When in doubt, verify the behavior of newLISP's internal parser by calling parse without optional arguments.

Symbols for variable names

1. The following rules apply to the naming of symbols used as variables or functions:
Variable symbols may not start with any of the following characters:
# ; " ' ( ) { } . , 0 1 2 3 4 5 6 7 8 9

2. Variable symbols starting with a + or - cannot have a number as the second character.

3. Any character is allowed inside a variable name, except for:
" ' ( ) : , and the space character. These mark the end of a variable symbol.

4. A symbol name starting with [ (left square bracket) and ending with ] (right square bracket) may contain any character except the right square bracket.

5. A symbol name starting with $ (dollar sign) is global. There are several of these symbols already built into newLISP and set and changed internally. This type of global symbol can also be created by the user.

All of the following symbols are legal variable names in newLISP:

myvar
A-name
X34-zz
[* 7 5 ()};]
*111*
-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Re: curly strings and symbols

Post by HPW »

Thanks for the explanation.

Regards

Hans-Peter
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Re: curly strings and symbols

Post by HPW »

Of cource it is a bit irritating:

Also from the help:
Instead of a " (double quote), a { (left curly bracket) and } (right curly bracket) can be used to delimit strings. This is useful when quotation marks need to occur inside strings.

Code: Select all

> (setq Test 10)
10
> (setq Test1 (string "Bla"Test"Bla1"))
Bla10Bla1
Since this is valid I had a longer bug-hunt because I thought I could simply replace the double quote.
Or should rule 3 to be changed so that curly brackets would not be allowed in symbols and would act like the double quote?
Hans-Peter

Locked