newLISP Fan Club

Forum => newLISP newS => Topic started by: cormullion on January 16, 2009, 03:51:10 PM

Title: double quotes
Post by: cormullion on January 16, 2009, 03:51:10 PM
I've been struggling with the following. The only way I can get it to work is by putting two single quotes in front of a symbol name:


(set 'columns '(No AtomicWeight Name Symbol MP BP Density EarthCrust DiscoveryYear Group IonizationEnergy))
(set 'select-fn '(and (> 'DiscoveryYear 1900) (< 'EarthCrust 5)))
(set 'row '(1 1.0079 "Hydrogen" "H" -259 -253 0.09 0.14 1776 1 13.5984))
(set 'field ''DiscoveryYear) ; like that
(eval (set-ref-all field  select-fn (row (find (eval field) columns))))


I want to replace every quoted symbol in 'select-fn' with its equivalent value in row. and field is to iterate through columns...



This works if I double-single-quote the field-name, but I can't do that and iterate over the list of columns. For some reason, (quote (quote x)) isn't the same as ' ' x is it?
Title:
Post by: Kazimir Majorinc on January 16, 2009, 08:15:09 PM
Yes, ' and quote are different. You can use letex or expand.
(dolist (j columns)
   (set-ref-all (expand ''j 'j)
                select-fn
                (row (find j columns))))
(dolist (j columns)
   (set-ref-all (letex((j j))''j)  
                select-fn
                (row (find j columns))))
Title:
Post by: cormullion on January 16, 2009, 11:55:46 PM
Thanks, Kazimir - that works great.



I had always thought ' and quote were interchangeable...
Title:
Post by: DrDave on January 17, 2009, 12:10:54 AM
Quote from: "cormullion"Thanks, Kazimir - that works great.



I had always thought ' and quote were interchangeable...


I also thought they were interchnageable. So perhaps one of the gurus will post an explanation of the difference, and maybe how it came about that we have both of them in the language.
Title:
Post by: Lutz on January 17, 2009, 05:10:37 AM
> (= (quote x) 'x)
true
> (= (quote 'x) ''x)
true
> (= (quote (quote x)) '(quote x))
true

;;;; but

> (= (quote (quote x)) ''x)
nil
> (= '(quote x) ''x))
nil




The "'" quote gets resolved during source code translation, wrapping the quoted cell into a protecting envelope. The function 'quote' does the same but during evaluation. The function 'quote' is more like the original Lisp 'quote'. The "'" quote is an optimization done during code translation.
Title:
Post by: cormullion on January 18, 2009, 09:11:06 AM
I see, but wouldn't claim to understand fully yet. I wasn't really aware of the difference between 'source-code translation' and 'evaluation'. For now I'm just glad that Kazimir showed me how to do it! :)
Title:
Post by: DrDave on January 18, 2009, 01:08:08 PM
Quote from: "cormullion"I see, but wouldn't claim to understand fully yet.

I'm on the same wagon! How about a different concrete example that might clear away a bit more of the fog.
Title:
Post by: Lutz on January 18, 2009, 03:02:44 PM
Quote ... difference between 'source-code translation' and 'evaluation' ...


... can be best explained with the two functions:



eval-string => translation + evaluation => "(+ 3 4)" => 7

read-expr => translation => "(+ 3 4)" => (+ 3 4)



the "'" quote is resolved during translation time, the function 'quote' is resolved during evaluation time.