newLISP Fan Club

Forum => newLISP in the real world => Topic started by: psilwen on August 12, 2014, 11:00:12 AM

Title: (setq 'a 3), what does it mean?
Post by: psilwen on August 12, 2014, 11:00:12 AM
(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
Title: Re: (setq 'a 3), what does it mean?
Post by: HPW on August 12, 2014, 11:22:45 AM
Hello,



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

(Autocad's autolisp does so)



Regards
Title: Re: (setq 'a 3), what does it mean?
Post by: Lutz on August 12, 2014, 11:53:56 AM
(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 .



> (setq 'a 2)
2
> a
nil
> (define (foo) (setq 'a 2))
(lambda () (setq 'a 2))
> (foo)
2
> foo
(lambda () (setq '2 2))
>
Title: Re: (setq 'a 3), what does it mean?
Post by: rickyboy on August 12, 2014, 12:17:47 PM
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.
Title: Re: (setq 'a 3), what does it mean?
Post by: TedWalther on August 13, 2014, 11:20:43 AM
My head hurts.
Title: Re: (setq 'a 3), what does it mean?
Post by: rrq on August 13, 2014, 03:44:02 PM
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?
Title: Re: (setq 'a 3), what does it mean?
Post by: rickyboy on August 13, 2014, 05:05:59 PM
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. :)
Title: Re: (setq 'a 3), what does it mean?
Post by: TedWalther on August 13, 2014, 05:39:13 PM
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.
Title: Re: (setq 'a 3), what does it mean?
Post by: psilwen on August 13, 2014, 10:21:05 PM
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.
Title: Re: (setq 'a 3), what does it mean?
Post by: Lutz on August 14, 2014, 07:05:15 AM
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.
Title: Re: (setq 'a 3), what does it mean?
Post by: TedWalther on August 14, 2014, 11:44:33 AM
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.
Title: Re: (setq 'a 3), what does it mean?
Post by: rrq on August 14, 2014, 10:39:39 PM
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)