Re: a bunch of questions about syntax

2017-01-26 Thread Alexander Burger
On Thu, Jan 26, 2017 at 11:35:20PM +0100, pd wrote:
> Alex, thanks a lot for your very clarifier reply (specially the procedural
> way of thinking which makes a lot of sense to me), I'm still confusing in a
> couple of things...

No problem!

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).


> I've read in docs that the ' prefix in a name of formal parameter when
> describing a funcion indicates it's a evaluated parameter  (even when the

Yes

> opposite is clearer to me , using ' to indicate a non-evaluated parameter
> following the quote notation you use when want to preserve something from
> evaluation)

That would also make sense. I think the notation in the docs mirrors *some*
typical call scenarios.


> 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.


> So I suppose the notation (dbs+ 'num . lst) refers to a function defined as
> (de dbs+ X . Z ...) and thus first parameter is binded to X and also must

Yes, (de dbs+ (X . Z) ..) to be precise.

> 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.

To indicate that an argument is *expected* to be a list, I usually use 'Lst'

   (de foo (Lst)
  ..

> mean a notation to express you *must* call a function using a list like (f
> (a b c)) and not (f a b c)

Note that (f (a b c)) does not mean that a list will be passed, but depends on
the return value of the function 'a'). Same for (f a b c), it depends on the
values of the symbols 'a', 'b', and 'c'.

There is no strict, static notation for the types of arguments to a function.
This is a dynamic issue.


> Also taking about dot, as you said you have to use delimiters to separate
> symbols and thus you must surround dot with spaces (or any other delimiter
> I suppose, probably you can write the weird sentence (a,.,b) as an
> alternative to (a . b) dotted pair), so I suppose dot is kind of operator
> (maybe a read macro as ' ?) anyway I think it would be interesting if dot

It is *similar* to a read macro, as it controls the behavior of the reader. I
would not call it a "macro", because it has no corresponding expanded or
evaluated representation, like:

   'abc -> (quote . abc)
   `(* 3 4) -> 12

Instead, it is Lisp "syntax", on the same level as parentheses etc.


> could act as an operator being associative to the right, so you can write:
> 
> ( a . b . c . d . NIL)
> 
> to be equal to
> 
> (a . (b . (c . (d . NIL
> 
> and also equal to  (a b c d)
> 
> does it have any sense?

It would be possible to change the reader to accept (a . b . c . d . NIL), but
I'm not sure at the moment. Would there be any advantage?

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Is there a shorter syntax for calling a method from a method in

2017-01-26 Thread Alexander Burger
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


Re: a bunch of questions about syntax

2017-01-26 Thread pd
Alex, thanks a lot for your very clarifier reply (specially the procedural
way of thinking which makes a lot of sense to me), I'm still confusing in a
couple of things...


I've read in docs that the ' prefix in a name of formal parameter when
describing a funcion indicates it's a evaluated parameter  (even when the
opposite is clearer to me , using ' to indicate a non-evaluated parameter
following the quote notation you use when want to preserve something from
evaluation) 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?

I mean, if I describe the function F as being:

  -  (F 'num lst) -> num

am I saying the same as if I describe it this way?:

  -  (F 'num . lst) -> num


if not, what is the difference?


> and what means the following notation?
> >
> >   -  (dbs . lst)
>
> This notation is meant to represent a function like
>
>(de dbs Lst ..)
>
> so that a call
>
>(dbs a b c d)
>
> binds (a b c d) to 'Lst'.
>
>(dbs a b c d) = (dbs . (a b c d))
>
>

So I suppose the notation (dbs+ 'num . lst) refers to a function defined as
(de dbs+ X . Z ...) and thus first parameter is binded to X and also must
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
mean a notation to express you *must* call a function using a list like (f
(a b c)) and not (f a b c)


Also taking about dot, as you said you have to use delimiters to separate
symbols and thus you must surround dot with spaces (or any other delimiter
I suppose, probably you can write the weird sentence (a,.,b) as an
alternative to (a . b) dotted pair), so I suppose dot is kind of operator
(maybe a read macro as ' ?) anyway I think it would be interesting if dot
could act as an operator being associative to the right, so you can write:

( a . b . c . d . NIL)

to be equal to

(a . (b . (c . (d . NIL

and also equal to  (a b c d)

does it have any sense?


Is there a shorter syntax for calling a method from a method in the

2017-01-26 Thread dean
i.e. I'm calling m1 from m2 using the same syntax as calling methods
externallybut just replacing *Obj with This.
No problem if not butIs there a shorter way e.g. like (: member)
instead of (get This 'member)
(class +Clss)
   (dm T ())
   (dm m1> () (setq Res 4))
   (dm m2> (Arg2) (+ (send 'm1> This) Arg2))

(setq *Obj (new '(+Clss)))
(prinl (format (send 'm2> *Obj 5)))


Re: a bunch of questions about syntax

2017-01-26 Thread Alexander Burger
Hi Pd,

>- three base data types: Numbers, Symbols and Cons Pairs (Lists),
>...
> suggesting dotted pairs are the same as lists, both are
> indistinguishable so it should be possible to write any list as a dotted
> pair, i. e. (1 2) = (1 . (2 . NIL)) but what is the list for (1 . 2) dotted
> pair?

Lists are a special kind of cons pairs. We call it a list if the last cell has
NIL in its CDR, just like in your example.

So both (1 2) and (1 . 2) are cons pairs. In fact, each cell in a list is a cons
pair), but only (1) or (1 2) is called a list.


> 2- In the same doc talking about function arguments you can read "A lambda
> expression always has a list of executable expressions as its CDR. The CAR,
> however, must be a either a list of symbols, or a single symbol ...

> a)   : (de foo (X Y . Z) # CAR is a list with a dotted-pair
> tail

Right

> According with the parameters rules the first is supposed to bind X to the
> first evaluated parameter, Y to the second and Z to the rest of parameters

Yes

> but here the rule to apply is the first one, car is a list of symbols (X, Y
> and Z the last two in the dotted pair Y.Z) so every symbol must be binded
> to evaluated parameters

No, the 'Z' means that the rest of the symbols is *not* evaluated.


> (foo (1 2 3 4))
> 
> should bind 1 to X, 2 to Y and 3 to Z discarding 4 but the examples says it
> really binds 1 to X, 2 to Y and (3 4) to Z thus effectively merging first

No. It binds X to (1 2 3 4), and both Y and Z to NIL


If you call

   (foo 1 2 3 4)

then it binds X to 1, Y to 2 and Z to (3 4).




> b)  : (de foo (X . @)   # CAR is a dotted-pair with '@'
> 
> This case is similar to the previous but merging first and second rules but
> in this case first rule doesn't apply because as comment remarks CAR is a
> dotted pair not a list


Perhaps it helps to think about this procedurally: While the list of formal
parameters is a cons pair (i.e. not atomic), the next symbol is popped of and
the evaluated parameter bound to it. Then, if the remaining piece is not NIL,
the rest of the list is bound to it unevaluated.

So if the "list" of formal parameters is just Z

   (de foo Z ..)
   (foo 1 2 3 4 5)

then 'Z' is bound to (1 2 3 4 5).

On the other hand, if it is (X Y . Z)

   (de foo (X Y . Z)
   (foo 1 2 3 4 5)

then first X is popped off

   : (setq Lst '(X Y . Z))
   -> (X Y . Z)

   : (pop 'Lst)
   -> X

so 'X' is bound to 1. 'Lst' is now

   : Lst
   -> (Y . Z)

again, we pop

   : (pop 'Lst)
   -> Y

so we bind Y to 2.

But now 'Lst' is

   : Lst
   -> Z

It became atomic! So we are back at the "simple" case above where we had

   (de foo Z ..)

and Z is bound to (3 4 5).
   

The same systematics apply to cases like

   (de foo @ ...)

and

   (de foo (X Y Z . @)

Does this make sense?



> and what means the following notation?
> 
>   -  (dbs . lst)

This notation is meant to represent a function like

   (de dbs Lst ..)

so that a call

   (dbs a b c d)

binds (a b c d) to 'Lst'.

   (dbs a b c d) = (dbs . (a b c d))



> 4- Usually in classical lisp syntax you must use dot surrounded by spaces
> to indicate a dotted pair, I supposed this will be the same in picolisp
> because of fixed point numbers notation so you always shoud use (sym . sym)

Yes. The dot is not a delimiter.

Atoms are delimited by these characters:

   " \t\n\r\\"'(),[]`~{}"


> to write a dotted paid in particular with transient symbols ("hello" .
> "world") but I saw in this lists messages seeming to use the notation

I would not write it this way, but always as ("hello" . "world").

However, ("hello"."world") is correctly read because the double qoutes
are delimiters.

Same with e.g. ("hello"("world")"!")


I hope I could clear up some smoke.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


a bunch of questions about syntax

2017-01-26 Thread pd
I was reading the picolip documents ref, tutorial and function reference
and I'm afraid I misunderstand some concepts, so I'm asking a bunch of
questions in the hope you can help to achieve a better picolisp
understanding

1- In the ref document it's said talking about types in picolisp:

   - three base data types: Numbers, Symbols and Cons Pairs (Lists),
   - the three scope variations of symbols: Internal, Transient and
   External, and
   - the special symbol NIL.

suggesting dotted pairs are the same as lists, both are
indistinguishable so it should be possible to write any list as a dotted
pair, i. e. (1 2) = (1 . (2 . NIL)) but what is the list for (1 . 2) dotted
pair?


2- In the same doc talking about function arguments you can read "A lambda
expression always has a list of executable expressions as its CDR. The CAR,
however, must be a either a list of symbols, or a single symbol, and it
controls the evaluation of the arguments to the executable function
according to the following rules:
When the CAR is a list of symbols For each of these symbols an argument is
evaluated, then the symbols are bound simultaneously to the results. The
body of the lambda expression is executed, then the VAL's of the symbols
are restored to their original values. This is the most common case, a
fixed number of arguments is passed to the function. Otherwise, when the
CAR is the symbol @ All arguments are evaluated and the results kept
internally in a list. The body of the lambda expression is executed, and
the evaluated arguments can be accessed sequentially with the args
, next
, arg
 and rest
 functions. This allows to
define functions with a variable number of evaluated arguments. Otherwise,
when the CAR is a single symbol The symbol is bound to the whole
unevaluated argument list. The body of the lambda expression is executed,
then the symbol is restored to its original value. This allows to define
functions with unevaluated arguments. Any kind of interpretation and
evaluation of the argument list can be done inside the expression body."Also
the doc said the rules for parameters may be combined and show several
examples:


a)   : (de foo (X Y . Z) # CAR is a list with a dotted-pair
tail
According with the parameters rules the first is supposed to bind X to the
first evaluated parameter, Y to the second and Z to the rest of parameters
but here the rule to apply is the first one, car is a list of symbols (X, Y
and Z the last two in the dotted pair Y.Z) so every symbol must be binded
to evaluated parameters, thus a funcion call like:

(foo (1 2 3 4))

should bind 1 to X, 2 to Y and 3 to Z discarding 4 but the examples says it
really binds 1 to X, 2 to Y and (3 4) to Z thus effectively merging first
and third rule, the question is why? since the CAR is not a single symbol
but a list and also the dotted-pair tail (Y.Z) is not a single symbol but a
dotted pair

b)  : (de foo (X . @)   # CAR is a dotted-pair with '@'

This case is similar to the previous but merging first and second rules but
in this case first rule doesn't apply because as comment remarks CAR is a
dotted pair not a list


3-  In the function reference I see several times functions described with
dots in parameter lists, I think it's related to question 2 and it is just
using the merging-rules parameters but what's the difference between these
two notations:

  -  (dbs+ 'num . lst)

  -  (delete 'any 'lst) -> lst

and what means the following notation?

  -  (dbs . lst)

4- Usually in classical lisp syntax you must use dot surrounded by spaces
to indicate a dotted pair, I supposed this will be the same in picolisp
because of fixed point numbers notation so you always shoud use (sym . sym)
to write a dotted paid in particular with transient symbols ("hello" .
"world") but I saw in this lists messages seeming to use the notation
("hello"."world") to write a dotted pair, is it allowed? or maybe is
another kind of data type?



thanks for your replies