Re: a bunch of questions about syntax
On Sat, Jan 28, 2017 at 02:35:09AM +0100, pd wrote: > sorry, I accidentally sent an incomplete message, here's the complete one > ... > >> > >> BTW, I thought again about the terminology of "list" versus "cons pairs" > >> and > >> plain "cells". "list" is a rather unprecise term, I feel it is not > >> limited to "a > >> chain of cells with NIL at the end". I use "list" for any sequence of > >> cells (as > >> opposed to other structures like "tree", "graph" or "set"). These include > >> also > >> e.g. "circular lists" like (1 2 3 .), which have no NIL at the end (in > >> fact, no > >> end at all). > >> > > Ok, so from this point of view every cons pair is a list even those with a > > dotted pair in the tail No, definitely not. I would not call (3 . 4) a list. Still, as I said, "list" is a rather unprecise term. Some people use the term "proper list" for a NIL-terminated list. > > I mean, with a NIL ending list you have an empty list condition (NIL) but > > how do you know a non-NIL ending list is empty? and since most functions No. Only the atom 'NIL' is the empty list. > > condition to finish processing the list I think it would be interesting to > > discriminate between those two kinds of lists. I think it does not matter. At least it is not very important. Every function in Lisp is free to treat its arguments as it likes. The PicoLisp interpreter doesn't care very much. Most list-processing functions do not check for NIL at the end, but whether the item is atomic or not In C: while (isCell(cdr(x = cdr(x In Asm: ld X (X CDR) # Args atom (X CDR) # more than one left? while z # Yes > > what about these two? are they equivalent? > > > > (f num lst) -> num > > (g num . lst) -> num No. 'f' takes two argument (supposed to evaluate to a number and a list), while 'g' takes an unlimited number of arguments (the first supposed to be a number after evaluation, the rest unspecified). > > of course it's the function body which determines the "type" of > > parameters, if the body applies a parameter to a function expecting a > > number, that parameter's type must be a number and not a symbol or list or > > the function call in the body will fail, but you use a notation for Right. > > describing functions just to help users know what kind of parameter you > > must provide, that's the reason to use that list of meaningful words, type > > is not enforced (not possible) but suggested to user using the function, > > right? Exactly. > > From this point of view my question is about the difference of using or > > not using dot when describing a function, for example, take the if > > description: > > > > (if 'any1 any2 . prg) -> any > > > > Would the description below describe the same function? > > > > (if 'any1 any2 prg) -> any A typical call of 'if' could be (if (testSomething) (doSomething1) (doSomething2) (doSomething3)) where any1 is the result of evaluating (testSomething) any2 is (doSomething1) prg is ((doSomething2) (doSomething3)) Perhaps it helps understanding if we remember that (if (testSomething) (doSomething1) (doSomething2) (doSomething3)) is the same as (if (testSomething) (doSomething1) . ((doSomething2) (doSomething3))) If 'if' were specified as in the second case (if 'any1 any2 prg), then we would need to call it as (if (testSomething) (doSomething1) ((doSomething2) (doSomething3))) to match the spec (if 'any1 any2 prg) and get the same bindings. > > (if T 3 (print "no")) # valid > > (if (< 2 2) 'x (print "yeah"))# valid > > (if T 3 4)# invalid > > because 4 is a number not a prg (a list) Yes, but the prg is (4), not 4. > > (if NIL (print "then") (print "else") (print "finally")) # a doubt here, > > ># I > think it's invalid because two executable expressions are two lists not one > prg (one list of executable expressions) No, it is perfectly valid. (print "then") is the "then" part, an 'exe' ((print "else") (print "finally")) is the "else" part, a 'prg' > (if (really?) (print (car *Glist)) NIL) # invalid because you cannot use > a NIL value as "else" return, you need to supply a executable expressions No, perfectly valid. The 'prg' is (NIL). Remember how a 'prg' is executed: Each expressions is evaluated, one after the other, and the result of the last one is the result of the whole 'prg'. The last expression evaluated here is NIL, so the result is NIL. > (if (really?) (print (car *Glist)) (NIL)) # so you must rewrite the This would crash, as the 'prg' is ((NIL)), thus the last expression is (NIL), and NIL is not a function. > The primary data types: > >- num - Number >- sym - Symbol >- lst - List > ... >- any - Anything: Any data type > It's not a matter of type endorsement but a kind of typ
Re: a bunch of questions about syntax
sorry, I accidentally sent an incomplete message, here's the complete one On Sat, Jan 28, 2017 at 1:51 AM, pd wrote: > Thanks again for your explanations Alex, still some comments... > > On Fri, Jan 27, 2017 at 8:16 AM, Alexander Burger > wrote: > >> >> >> BTW, I thought again about the terminology of "list" versus "cons pairs" >> and >> plain "cells". "list" is a rather unprecise term, I feel it is not >> limited to "a >> chain of cells with NIL at the end". I use "list" for any sequence of >> cells (as >> opposed to other structures like "tree", "graph" or "set"). These include >> also >> e.g. "circular lists" like (1 2 3 .), which have no NIL at the end (in >> fact, no >> end at all). >> > > Ok, so from this point of view every cons pair is a list even those with a > dotted pair in the tail > > But I think it's interesting to distinguish between two different kind of > lists, those having a NIL symbol in last cell CDR (let's say ending in NIL > symbol) and with a non NIL in las cell CDR (those ending in a symbol not > NIL) just because of almost every function dealing with lists assume they > belong to NIL-ending kind. > > I mean, with a NIL ending list you have an empty list condition (NIL) but > how do you know a non-NIL ending list is empty? and since most functions > dealing with lists have a recursive pattern looking for an empty list > condition to finish processing the list I think it would be interesting to > discriminate between those two kinds of lists. > > For example, let's define f as: > > (de f (L) (print (car L)) (if (<> NIL (cdr L)) (f (cdr L > > then f is well defined for NIL ending lists but fails with non-NIL ending > lists > > > > >> > but when describing functions ' is a notation mark with a >> > semantic, what is the semantic of dot notation mark when used in formal >> > parameters in function description? >> > >> > I mean, you have these two notations for functions: >> > >> > - (dbs+ 'num . lst) >> > >> > - (delete 'any 'lst) -> lst >> > >> > are they applied the same? with the same kind of parameters? >> >> The functions behave differently. (dbs+ 'num . lst) means that the the >> function >> takes an unlimited number of arguments, where only the first one is >> evaluated, >> while (delete 'any 'lst) takes two evaluated arguments. > > > what about these two? are they equivalent? > > (f num lst) -> num > (g num . lst) -> num > > >> >> > evaluate to a number and rest of parameters will be bound to Z, so you >> call >> > this function like (dbs+ 4 a b c) , what notation will you use to >> express >> > you have to pass a list as parameter to a function? maybe (dbs+ 'lst) >> ? I >> >> These function definitions say nothing about the types of the arguments >> like >> number, list etc. This is determined by the behavior of the function's >> body. >> >> > of course it's the function body which determines the "type" of > parameters, if the body applies a parameter to a function expecting a > number, that parameter's type must be a number and not a symbol or list or > the function call in the body will fail, but you use a notation for > describing functions just to help users know what kind of parameter you > must provide, that's the reason to use that list of meaningful words, type > is not enforced (not possible) but suggested to user using the function, > right? > > so a function described as(f 'num 'num) informs that function f > expects two parameters being numbers and since parameters are evaluated > it's the value what is expected to be numers, so you can call f as (f 1 2) > or (f a b) or even (f (x y z) 3) provided that values of symbols a and b > are numbers and the result of x function call (x y z) returns a number but > sure you cannot call f as (f (1 2)) or (f 'x 4) > > From this point of view my question is about the difference of using or > not using dot when describing a function, for example, take the if > description: > > (if 'any1 any2 . prg) -> any > > Would the description below describe the same function? > > (if 'any1 any2 prg) -> any > > Even more, having into account notation used for describing functions I > know: > > any - Anything: Any data type > prg - Prog-Body: A list of executable expressions (run) > > so from description of function "if" which is "Conditional execution: If > the condition any1 evaluates to non-NIL, any2 is evaluated and returned. > Otherwise, prg is executed and the result returned." I undestand the > "then" clause is any2 which gets evaluated when evaluated any1 is T and > also it could be any type of value while prg is the "else" clause being > evaluated only if evaluation of any1 returns NIL and also it is a list of > executable expressions, from this I understand the following is a list of > valid and invalid if function calls: > > (if T 3 (print "no")) # valid > (if (< 2 2) 'x (print "yeah"))# valid > (if T 3 4)
Re: a bunch of questions about syntax
Thanks again for your explanations Alex, still some comments... On Fri, Jan 27, 2017 at 8:16 AM, Alexander Burger wrote: > > > BTW, I thought again about the terminology of "list" versus "cons pairs" > and > plain "cells". "list" is a rather unprecise term, I feel it is not limited > to "a > chain of cells with NIL at the end". I use "list" for any sequence of > cells (as > opposed to other structures like "tree", "graph" or "set"). These include > also > e.g. "circular lists" like (1 2 3 .), which have no NIL at the end (in > fact, no > end at all). > Ok, so from this point of view every cons pair is a list even those with a dotted pair in the tail But I think it's interesting to distinguish between two different kind of lists, those having a NIL symbol in last cell CDR (let's say ending in NIL symbol) and with a non NIL in las cell CDR (those ending in a symbol not NIL) just because of almost every function dealing with lists assume they belong to NIL-ending kind. I mean, with a NIL ending list you have an empty list condition (NIL) but how do you know a non-NIL ending list is empty? and since most functions dealing with lists have a recursive pattern looking for an empty list condition to finish processing the list I think it would be interesting to discriminate between those two kinds of lists. For example, let's define f as: (de f (L) (print (car L)) (if (<> NIL (cdr L)) (f (cdr L then f is well defined for NIL ending lists but fails with non-NIL ending lists > > but when describing functions ' is a notation mark with a > > semantic, what is the semantic of dot notation mark when used in formal > > parameters in function description? > > > > I mean, you have these two notations for functions: > > > > - (dbs+ 'num . lst) > > > > - (delete 'any 'lst) -> lst > > > > are they applied the same? with the same kind of parameters? > > The functions behave differently. (dbs+ 'num . lst) means that the the > function > takes an unlimited number of arguments, where only the first one is > evaluated, > while (delete 'any 'lst) takes two evaluated arguments. what about these two? are they equivalent? (f num lst) -> num (g num . lst) -> num > > > evaluate to a number and rest of parameters will be bound to Z, so you > call > > this function like (dbs+ 4 a b c) , what notation will you use to > express > > you have to pass a list as parameter to a function? maybe (dbs+ 'lst) ? > I > > These function definitions say nothing about the types of the arguments > like > number, list etc. This is determined by the behavior of the function's > body. > > of course it's the function body which determines the "type" of parameters, if the body applies a parameter to a function expecting a number, that parameter's type must be a number and not a symbol or list or the function call in the body will fail, but you use a notation for describing functions just to help users know what kind of parameter you must provide, that's the reason to use that list of meaningful words, type is not enforced (not possible) but suggested to user using the function, right? so a function described as(f 'num 'num) informs that function f expects two parameters being numbers and since parameters are evaluated it's the value what is expected to be numers, so you can call f as (f 1 2) or (f a b) or even (f (x y z) 3) provided that values of symbols a and b are numbers and the result of x function call (x y z) returns a number but sure you cannot call f as (f (1 2)) or (f 'x 4) >From this point of view my question is about the difference of using or not using dot when describing a function, for example, take the if description: (if 'any1 any2 . prg) -> any Would the description below describe the same function? (if 'any1 any2 prg) -> any Even more, having into account notation used for describing functions I know: any - Anything: Any data type prg - Prog-Body: A list of executable expressions (run) so from description of function "if" which is "Conditional execution: If the condition any1 evaluates to non-NIL, any2 is evaluated and returned. Otherwise, prg is executed and the result returned." I undestand the "then" clause is any2 which gets evaluated when evaluated any1 is T and also it could be any type of value while prg is the "else" clause being evaluated only if evaluation of any1 returns NIL and also it is a list of executable expressions, from this I understand the following is a list of valid and invalid if function calls: (if T 3 (print "no")) # valid (if (< 2 2) 'x (print "yeah"))# valid (if T 3 4)# invalid because 4 is a number not a prg (a list) (if NIL (print "then") (print "else") (print "finally")) # a doubt here, I think it's invalid because two executable expressions are two lists not one prg (one list of executable expressions) prg - Prog-Body: A list of executable expressio
Re: (NIL) vs Nothing
Hi Dean, > (de fltr (Buf Ln) >(setq New_buf (mapcar '((Ele) (pack (tail (- (length Ln)) (chop Ele > (filter '((Ele) (pre? Ln Ele)) Buf > ... > #: (fltr '(aa ab) 'ab) > #-> (NIL) You can use 'extract' to get exactly the results you need: (de fltr (Buf Ln) (let N (inc (length Ln)) (extract '((Ele) (when (pre? Ln Ele) (pack (nth (chop Ele) N)) ) ) Buf ) ) ) Perhaps 'match' is more elegant than 'pre?' and 'nth' or 'tail': (de fltr (Buf Ln) (let Pat (conc (chop Ln) '(@Rest)) (use @Rest (extract '((Ele) (and (match Pat (chop Ele)) (pack @Rest)) ) Buf ) ) ) ) In both cases: : (msg (fltr '(aa ab abc) 'ab)) -> ("c") ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
re (NIL) vs nothing
re my last post/thread I don't want to waste anyone's time so please hold fire... I've split the filtering and chopping in two and even the filtered member LIst is disappearing (as a result of just filtering (when it shouldn't) so the problem doesn't look like it's to do with chopping the values down to NIL. I'll keep working on it. Best Regards Dean
(NIL) vs Nothing
I've got this filtering function (de fltr (Buf Ln) (setq New_buf (mapcar '((Ele) (pack (tail (- (length Ln)) (chop Ele (filter '((Ele) (pre? Ln Ele)) Buf If any element 'Ele' of Buf starts with Ln it get's put into New_buf but not before the the Ln part is chopped off the front. In an ideal world any matching Ele will be the SAME length as Ln but I've found that Some matches are split over Consecutive lines. The first example below shows that Ln=Ele i.e. returning (NIL)Any NIL in New_buf will end the search satisfactorily...I only need one! #: (fltr '(aa ab) 'ab) #-> (NIL) These show what happens when the match is split over multiple lines i.e. it gets there in the end. #: (setq L (fltr '(aa ab) 'a)) #-> ("a" "b") #: (fltr L 'b) #-> (NIL) My problem is that the "real" code is more involved and in order not to have to write it out in "fully" for each time I use it (3) I thought I'd use objects. Whilst the 'ab match properly returns (NIL)the split match i.e. 'a and then 'b cause the member New_buf to disappear altogether from the object i.e. not return (NIL) like above. I thought I'd test if (NIL) means nothing but get that NIL in (NIL) is undefined. (if (= NIL (NIL)) (prinl "yes") (prinl "no")) #!? (NIL) #NIL -- Undefined Is there a good reason why New_buf should disappear rather hold (NIL) when this is done in an object and is NIL in (NIL) undefined when it gets returned as shown above? Any advice much appreciated I could move around this problem by doing the filtering and chopping in two stages with some testing in between but thought it would help with my development to ask.
Subscribe
Hello =?utf-8?B?0JLQuNC60YLQvtGA?= :-) You are now subscribed -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: Is there a shorter syntax for calling a method from a method in
Hi Alex That's great...thank you very much. Best Regards Dean On 27 January 2017 at 06:53, Alexander Burger wrote: > Hi Dean, > > > i.e. I'm calling m1 from m2 using the same syntax as calling methods > > externallybut just replacing *Obj with This. > > Yes, that's fine. > > > No problem if not butIs there a shorter way e.g. like (: member) > > instead of (get This 'member) > > Yes, (: member) is the same as (get This 'member) or (; This member). > 'member' > doesn't show up in your code though. > > > (class +Clss) > >(dm T ()) > >(dm m1> () (setq Res 4)) > >(dm m2> (Arg2) (+ (send 'm1> This) Arg2)) > > Instead of (send 'm1> This) you would usually write (m1> This) > > > > (setq *Obj (new '(+Clss))) > > (prinl (format (send 'm2> *Obj 5))) > > and (m2> Obj 5) > > ♪♫ Alex > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >