SBCL to newLISP

Started by kanen, June 28, 2010, 08:46:00 PM

Previous topic - Next topic

m i c h a e l

#15
Quote from: "Tim"Michael, I've never used setf like that.




I don't normally use setf for variable assignment either, but the comment from Greg (itistoday) sparked the new test. I was really surprised by the results. I assumed setf was slower since it's used, as you quote:


Quote from: "newLISP Manual & Reference"when setting list or array references


I wonder if there's a good reason to not use setf in place of set and . . . wait. I forgot to test setq:


(define (test-setq-once) (setq a 1 b 2 c 3 d 4 e 5 f 6 g 7))

(define (test-setq-multiple)
(setq a 1)
(setq b 2)
(setq c 3)
(setq d 4)
(setq e 5)
(setq f 6)
(setq g 7)
)


(time (test-setq-once) 1000000) ;=> 381.148
(time (test-setq-multiple) 1000000) ;=> 525.763


So it looks like both setq and setf are faster than set. I ran these tests multiple times, and the q and f versions are consistently faster. Lutz, should we be using setq in place of set for the slight speed increase?



m i c h a e l

itistoday

#16
Quote from: "m i c h a e l"So it looks like both setq and setf are faster than set. I ran these tests multiple times, and the q and f versions are consistently faster. Lutz, should we be using setq in place of set for the slight speed increase?


I don't think setq should be used at all, there's no reason for it as it's just an alias for setf (which is why you're seeing those results), and included for compatibility with old code.



I originally thought set was faster than setf for multiple assignments, but it seems like I must have made a mistake in those benchmarks, so setf is faster for everything. So, I don't know about you, but for consistency and speed I'm going to use setf for everything (unless I explicitly need to set on a symbol, which happens often enough, in which case there's no choice but to use set).
Get your Objective newLISP groove on.

xytroxon

#17
setq setf !

syntax: (setq place-1 exp-1 [place-2 exp-2 ... ])



setq and setf work alike in newLISP and set the contents of a symbol, list, array or string or of a list, array or string place reference. Like set, setq and setf can take multiple argument pairs. Although both setq and setf point to the same built-in function internally, throughout this manual setq is used when setting a symbol reference and setf is used when setting list or array references.



-- xytroxon
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976

itistoday

#18
Yes, though the manual does use that convention for some reason, I don't see the point. I see it as adding confusion to my code and giving me one more thing to have to worry about (should I use setf or setq here?). There's no reason to burden yourself with unnecessary complexity.
Get your Objective newLISP groove on.

m i c h a e l

#19
Here's one more way to set variables:


> (define a 1)
1
> a
1
> _


Of course, define cannot be used to do multiple assignments. I think Lutz said this form was designed for Scheme programmers to feel more at home.



m i c h a e l