(setq 'a 3), what does it mean?
(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
(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")
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).
(Autocad's autolisp does so)
Regards
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
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
> a
nil
> (define (foo) (setq 'a 2))
(lambda () (setq 'a 2))
> (foo)
2
> foo
(lambda () (setq '2 2))
>
Re: (setq 'a 3), what does it mean?
Yes!^h^h^h^hpsilwen wrote:(setq 'a 3) equivalent to (set ''a 3)?
No. See Lutz's comment above. (Surprised me, btw. :))
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.psilwen wrote:but result is:
(set ''a 3) =>
ERR: symbol expected in function set : ''a
Last edited by rickyboy on Wed Aug 13, 2014 6:53 pm, edited 1 time in total.
(λx. x x) (λx. x x)
-
- Posts: 608
- Joined: Mon Feb 05, 2007 1:04 am
- Location: Abbotsford, BC
- Contact:
Re: (setq 'a 3), what does it mean?
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.
-
- Posts: 228
- Joined: Mon Jun 02, 2014 1:40 am
- Location: Melbourne, Australia
Re: (setq 'a 3), what does it mean?
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, 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.
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?
Re: (setq 'a 3), what does it mean?
Yes, I did not expect this.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.
Code: Select all
> (quote? ''x)
true
> (quote? (quote (quote x)))
nil
Head hurty. Tommy no likey. :)ralph.ronnquist wrote:how's the head now?
(λx. x x) (λx. x x)
-
- Posts: 608
- Joined: Mon Feb 05, 2007 1:04 am
- Location: Abbotsford, BC
- Contact:
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.
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.
Re: (setq 'a 3), what does it mean?
yes, sometimes some features of newlisp make me confusion.
for instance, in-place modification
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.
for instance, in-place modification
Code: Select all
(define (myinc)
(inc 0))
(myinc) => 1
myinc = > (lambda () inc 1)
(myinc) => 2
myinc => (lambda () inc 2)
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")
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:
On the level of evaluation both do the same, which is creating a do-nothing evaluation shield.
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
-
- Posts: 608
- Joined: Mon Feb 05, 2007 1:04 am
- Location: Abbotsford, BC
- Contact:
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.
-
- Posts: 228
- Joined: Mon Jun 02, 2014 1:40 am
- Location: Melbourne, Australia
Re: (setq 'a 3), what does it mean?
psilwen wrote:
Maybe you can use gunzip?2) how to uncompress http gzip stream in memory with zlib? who has complete example of it. code of newlisp, not c/c++
Code: Select all
(exec "gunzip -c" gzipped-string)