## (setq 'a 3), what does it mean?

Q&A's, tips, howto's

### (setq 'a 3), what does it mean?

(setq a 2) => 2
(setq 'a 3) => 3
(eval a) => 2
(eval 'a) => 2
(eval ''a) => a

(setq a 2) equivalent to (set 'a 2)
(setq 'a 3) equivalent to (set ''a 3)?
but result is:
(set ''a 3) =>
ERR: symbol expected in function set : ''a
(reverse "newlisp")
psilwen

Posts: 21
Joined: Thu Jul 03, 2014 5:25 am

### Re: (setq 'a 3), what does it mean?

Hello,

I would expect that (setq 'a 3) should throw the same error as with (set ''a 3).

Regards
Hans-Peter
HPW

Posts: 1374
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany

### Re: (setq 'a 3), what does it mean?

(setq 'a 2) will do in-place modification of symbol a. For more examples see the last chapter on this page: http://www.newlisp.org/index.cgi?Closures .

Code: Select all
`> (setq 'a 2)2> anil> (define (foo) (setq 'a 2))(lambda () (setq 'a 2))> (foo)2> foo(lambda () (setq '2 2))> `
Lutz

Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm

### Re: (setq 'a 3), what does it mean?

psilwen wrote:(setq 'a 3) equivalent to (set ''a 3)?

Yes!^h^h^h^h
No. See Lutz's comment above. (Surprised me, btw. :))

psilwen wrote:but result is:
(set ''a 3) =>
ERR: symbol expected in function set : ''a

Yes, this is also correct, because that code induces a type error. set's first argument should be a symbol, but ''a (which can be thought of as shorthand for (quote (quote a))) evaluates to (quote a) which is of type quote, not symbol.
Last edited by rickyboy on Wed Aug 13, 2014 6:53 pm, edited 1 time in total.
(λx. x x) (λx. x x)
rickyboy

Posts: 582
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

### Re: (setq 'a 3), what does it mean?

Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.
TedWalther

Posts: 605
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC

### Re: (setq 'a 3), what does it mean?

Yes, this is also correct, because that code induces a type error. set's first argument should be a symbol, but ''a (which can be thought of as shorthand for (quote (quote a))) evaluates to (quote a) which is of type quote, not symbol.

Whilst set versus setq is not on my list of confusions, the pair ' versus quote is, and usually I manage to ignore the existence of the quote word. But, with TedWhalter half-way there, I thought it worth to point out that apparently no phrase without ' (directly or indirectly) in it will make the quote? predicate true.

Indeed, the explanation is clear and valid and sensible, but maybe a bit liberal on the use of the word "type", because (quote (quote a)) as well as '(quote a) make list? true and quote? false, wherease both (quote 'a) as well as ''a make list? false and quote? true.

ralph.ronnquist

Posts: 202
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

### Re: (setq 'a 3), what does it mean?

ralph.ronnquist wrote:Whilst set versus setq is not on my list of confusions, the pair ' versus quote is, and usually I manage to ignore the existence of the quote word. But, with TedWhalter half-way there, I thought it worth to point out that apparently no phrase without ' (directly or indirectly) in it will make the quote? predicate true.

Yes, I did not expect this.

Code: Select all
`> (quote? ''x)true> (quote? (quote (quote x)))nil`

Head hurty. Tommy no likey. :)
(λx. x x) (λx. x x)
rickyboy

Posts: 582
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

### Re: (setq 'a 3), what does it mean?

The thing I like the most about newLISP is that it has the least amount of "surprise" compared to other Lisps. And my ideas of "surprise" come from my C/shell/Unix background.

So, with the recent addition to the get-string function, I found myself again "surprised"... because the "chunk" size changes if you put the magic values of '\000\000' or '\000\000\000\000' in as delimiters. I feel like the less surprising thing would be to have get-bytes be raw data, and get-string be for getting strings of characters, no matter what the format.

Principle of Least Surprise. Makes my head feel clear and powerful.

Lately, I find myself getting more and more surprised. Every surprise means a gotcha, means yet another bit of state to hold in my head when programming.
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.
TedWalther

Posts: 605
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC

### Re: (setq 'a 3), what does it mean?

yes, sometimes some features of newlisp make me confusion.

for instance, in-place modification
Code: Select all
`(define (myinc)    (inc 0))(myinc) => 1myinc = > (lambda () inc 1)(myinc) => 2myinc => (lambda () inc 2)`

of course, this feature be really good. Just I've never seen in other languages.

i am learning newlisp in effort.

thanks all.

by the way,

1) i knowns win32demo.lsp. but is there win32gui module written using newlisp FOOP?

2) how to uncompress http gzip stream in memory with zlib? who has complete example of it. code of newlisp, not c/c++

i want to extract HTTP headers, such as Cookie..., and HTTP Body, but "get-url" cannot do it for me. I had to write my own one.

but i don't know how to do :(

in xmlhttp,we can do

make things so simple.

Does any suggestion? more detail more well.

(reverse "newlisp")
psilwen

Posts: 21
Joined: Thu Jul 03, 2014 5:25 am

### Re: (setq 'a 3), what does it mean?

quote and are not the same. The quote is a function executed at run-time the gets resolved at reader/compile time.

Before evaluation (quote x) is a list expression but ‘x is a quoted x. Therefore:
Code: Select all
`; one is a quoted symbol the other a list:(quote? ''x) => true(list? '(quote x)) => true; on the top level both evaluate to the same:(= (quote 'x) ''x) => true(= (quote (quote x)) '(quote x)) => true; and(quote? (quote 'x)) => true; but(= '(quote x) ''x) => nil; and(quote? '(quote x)) => nil`

On the level of evaluation both do the same, which is creating a do-nothing evaluation shield.
Lutz

Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm

### Re: (setq 'a 3), what does it mean?

That sounds a lot clearer. Guess there was some Paul Graham macro tutorial stuff still rattling around in my brain. The way Paul Graham taught it, ' actually is a macro that expands to (quote). And in newLisp, it behaves a little bit like a macro, even though there are no Common Lisp style macros.
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.
TedWalther

Posts: 605
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC

### Re: (setq 'a 3), what does it mean?

psilwen wrote:
2) how to uncompress http gzip stream in memory with zlib? who has complete example of it. code of newlisp, not c/c++

Maybe you can use gunzip?

Code: Select all
`(exec "gunzip -c" gzipped-string)`
ralph.ronnquist

Posts: 202
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia