why setf don't work?

Pondering the philosophy behind the language

why setf don't work?

Postby psilwen » Tue Aug 01, 2017 3:03 pm

Code: Select all
newLISP v.10.7.1 32-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h

> (struct 'RECT "long" "long" "long" "long")
RECT
> (unpack RECT (pack RECT 1 2 3 4))
(1 2 3 4)
> ((unpack RECT (pack RECT 1 2 3 4)) 0)
1
> (setf ((unpack RECT (pack RECT 1 2 3 4)) 0) 5)

ERR: symbol is protected : RECT
> (setq r (unpack RECT (pack RECT 1 2 3 4)))
(1 2 3 4)
> (setf (r 0) 5)
5
> r
(5 2 3 4)


why setf do in-place modifying don't work?
but
Code: Select all
> (setf ('(1 2 3 4) 0) 5)
5
> (setf ((list 1 2 3 4) 0) 5)
5
(reverse "newlisp")
psilwen
 
Posts: 19
Joined: Thu Jul 03, 2014 5:25 am

Re: why setf don't work?

Postby Lutz » Tue Aug 01, 2017 7:22 pm

Thanks for this discovery, the protection status of RECT should'nt be an issue in that expression as only the evaluation result of it is changed in place. Fixed now:

Code: Select all
newLISP v.10.7.3 64-bit on OSX IPv4/6 UTF-8 libffi, options: newlisp -h

>  (struct 'RECT "long" "long" "long" "long")
RECT
> (setf ((unpack RECT (pack RECT 1 2 3 4)) 0) 5)
5
>


http://newlisp.nfshost.com/downloads/de ... nprogress/
Lutz
 
Posts: 5230
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California


Return to Whither newLISP?

Who is online

Users browsing this forum: No registered users and 1 guest