List or quoted List

Q&A's, tips, howto's

List or quoted List

Postby ssqq » Thu May 29, 2014 11:36 pm

function map accept a quoted list as its seconds arguments:

(map inc '(1 2 3 4 5))

but above expression returned a list? or a quoted list? I think its should be a quoted list, because it could used with second map:

(map inc (map inc '(1 2 3 4)))

I don't know if it is a macro with map, but the expression with map is evaluted with some delay.

How to know a primitive function is macro or common function?

The evaluted order about primitive function? I know `eval` is first should be evaluate than `println`.
ssqq
 
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

Re: List or quoted List

Postby cormullion » Fri May 30, 2014 8:41 am

(map inc '(1 2 3 4 5))
but above expression returned a list? or a quoted list?


It returns an unevaluated list:

Code: Select all
(2 3 4 5)


As does:

Code: Select all
'(1 2 3 4)
(1 2 3 4)


which is why you can do:

Code: Select all
(map inc (map inc '(1 2 3 4))
;-> (3 4 5 6)


I don't think built-in functions are exactly macros, but many of them have special behaviour: e.g. if fortunately does not evaluate all the expressions passed to it. If it did, programming would be very difficult...
cormullion
 
Posts: 2037
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W

Re: List or quoted List

Postby ssqq » Sat May 31, 2014 12:25 am

I think must have a type of data structure -> 'lazy-list' in newLISP, which would not be evaluted when passed into function as argument. most of list processing function would return a 'lazy-list'.
ssqq
 
Posts: 88
Joined: Sun May 04, 2014 12:49 pm


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 2 guests

cron