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

Started by psilwen, August 12, 2014, 11:00:12 AM

Previous topic - Next topic

psilwen

(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\")

HPW

#1
Hello,



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

(Autocad's autolisp does so)



Regards
Hans-Peter

Lutz

#2
(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">http://www.newlisp.org/index.cgi?Closures .



> (setq 'a 2)
2
> a
nil
> (define (foo) (setq 'a 2))
(lambda () (setq 'a 2))
> (foo)
2
> foo
(lambda () (setq '2 2))
>

rickyboy

#3
Quote from: "psilwen"(setq 'a 3) equivalent to (set ''a 3)?

Yes!^h^h^h^h

No.  See Lutz's comment above. (Surprised me, btw. :))


Quote from: "psilwen"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.
(λx. x x) (λx. x x)

TedWalther

#4
My head hurts.
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.

rrq

#5
QuoteYes, 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.



how's the head now?

rickyboy

#6
Quote from: "ralph.ronnquist"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.


> (quote? ''x)
true
> (quote? (quote (quote x)))
nil

Quote from: "ralph.ronnquist"how's the head now?

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

TedWalther

#7
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 '0000' or '00000000' 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.

psilwen

#8
yes, sometimes some features of newlisp make me confusion.



for instance, in-place modification

(define (myinc)
    (inc 0))

(myinc) => 1
myinc = > (lambda () inc 1)
(myinc) => 2
myinc => (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?



deal with BUTTON,TEXTBOX,LISTBOX,MENU,LISTVIEW,TREEVIEW control,etc



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



getResponseHeader

getAllResponseHeaders



make things so simple.



Does any suggestion?  more detail more well.



thanks in advance.
(reverse \"newlisp\")

Lutz

#9
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:

; 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.

TedWalther

#10
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.

rrq

#11
psilwen wrote:
Quote2) 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?


(exec "gunzip -c" gzipped-string)