Re: Build transient value on the fly

2014-07-28 Thread Tomas Hlavaty
Hi Christophe,

 No problem for Display, but hello should spontaneously have its value
 changed to some XML containing the string hello.

in other words, you want to use the transient symbol hello as a
variable?  What is preventing you?  It's often done in PicoLisp.

(let hello 123
   (println hello) )

(let hello xmlhello/xml
   (println hello) )

 The real problem is with transient symbols. Or maybe I missed something?

There is no problem with transient symbols.  I would recommend reading
PicoLisp documentation on the topic.  Alex and Thorsten did very good
job with that.

If your problem is that you don't have a reference to that transient
symbol in your code due to being out of that transient scope, you can
always create a function in that transient scope which will have a
reference to that transient symbol and will do the desired manipulation.

Cheers,

Tomas
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Build transient value on the fly

2014-07-28 Thread Christophe Gragnic
On Mon, Jul 28, 2014 at 9:27 AM, Tomas Hlavaty t...@logand.com wrote:
 Hi Christophe,

 No problem for Display, but hello should spontaneously have its value
 changed to some XML containing the string hello.

 in other words, you want to use the transient symbol hello as a
 variable?  What is preventing you?

The problem is that I would like to avoid maintaining a list of
all transient that will be used. The idea was to automatically,
or spontaneously, transform the value of _any_ transient
using its name as a base.
This would allow programs written in an embedded domain-specific
language to be exported with different formats, considering
that this embedded language would be reprogrammed.
And transient symbols too.


chri

-- 

http://profgra.org/lycee/ (site pro)
http://delicious.com/profgraorg (liens, favoris)
https://twitter.com/profgraorg
http://microalg.info
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Subscribe

2014-07-28 Thread S R



Subscribe

2014-07-28 Thread S Pico



Differences in mapping functions

2014-07-28 Thread S Pico





I am often confused between the variants of the map functions: map, mapc, 
mapcar, mapcan, mapcon, maplist. 

The other related ones are easier because of the names: fish, filter, pick, 
extract ...


Their descriptions are very much alike, differing in maybe one line. Also, when 
I want to use it is hard to know which one I want, without going back to 
reference and reading all the descriptions.

Is there a short one-line synposis/organization of these functions with the key 
words, and/or a mnemonic that you may use to remember the differences?
e.g Apply to each element: mapc, mapcar, mapcan
   Apply to CDR: map, mapcon, maplist
   Return value : 

   Destructively concatenated list: mapcan, mapcon
   Result of each application: map, mapc
   List of all results: maplist, mapcar

   Destructive: mapcan, mapcon

But this organization does not seem to help much .. maybe there is a better way.

Thanks 

Srini

Understanding the later function

2014-07-28 Thread S Pico


I am trying to understand this example from the reference:
(prog1  # Parallel background calculation of square numbers (mapcan '((N) 
(later (cons) (* N N))) (1 2 3 4)) (wait NIL (full @)) )

Could you please explain how it works, because it has many interrelated pieces: 
cons,mapcan, wait that I thought I understood individually but still I do not 
understand the example.

But it is a very practical example, so I would like to understand it fully.

Also, what is the role of prog1. Does it control what is passed to the wait?

Another confusing thing is the @. How does one find which of the previous 
functions updated the @, and which did not. I know that control functions 
generally update the @, but still it is difficult to read the above example and 
decide where the @ is being generated (perhaps only for a newcomer like me).

Thanks
Srini

Re: Differences in mapping functions

2014-07-28 Thread Alexander Burger
Hi Srini,

 I am often confused between the variants of the map functions: map,
 mapc, mapcar, mapcan, mapcon, maplist.

Yes, indeed. The names of these 6 functions are historic, they are in
most Lisp variants since early on.


 Is there a short one-line synposis/organization of these functions
 with the key words, and/or a mnemonic that you may use to remember the
 differences?

There is a kind of systematic pattern. All 6 functions take an argument
funtion and one or several lists. But they differ in whether they

   1. pass the whole (rest)list to the function, or only the CAR.

   2. build a result list or not (i.e. whether they return something
  useful or are just for the side-effects).

   3. build the result list destructively (using the equivalent of 'con'
  or 'conc') or non-destructively (using 'cons' or 'append').


   Wole list Only CAR
  --+-+---
  No result | map |mapc
| |
  append|maplist  |   mapcar
| |
  concat|mapcon   |   mapcan


The logic of the naming might be (my interpretation):

   * The c in 'mapc' means CAR, as does the car in 'mapcar'

   * 'maplist' passes the whole list, while 'mapcar' takes the CAR

   * The con in 'mapcon' means concat while the can in
 'mapcan' replaces the o with an a from CAR.

Note that you can implement ALL these 6 functions using 'mapcon'. So
'mapcon' is the mother of all mapping functions (as also of 'find',
'filter' and so on). For example, instead of

   : (mapcar inc (1 2 3))
   - (2 3 4)

you could as well write

   : (mapcon '((L) (cons (inc (car L (1 2 3))
   - (2 3 4)

or instead of

   : (mapc println (1 2 3))
   1
   2
   3

you could write

   : (mapcon '((L) (println (car L)) NIL) (1 2 3))
   1
   2
   3

and so on.

In general, all functions in the Only CAR column above can be replaced
by the Whole list functions if the argument function takes car of
applying 'car' to the argument list.

I hope this clears things up a little.

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


Re: Understanding the later function

2014-07-28 Thread Alexander Burger
Hi Srini,

 I am trying to understand this example from the reference:
 (prog1  # Parallel background calculation of square numbers
(mapcan '((N) (later (cons) (* N N))) (1 2 3 4))
(wait NIL (full @)) )

 Could you please explain how it works, because it has many
 interrelated pieces: cons,mapcan, wait that I thought I understood
 individually but still I do not understand the example.

This call to 'prog1' executes two expressions, returning the result of
the first one, but _after_ executing the second one.

The first expression calls 'mapcan' on the list (1 2 3 4), by applying
the function

   ((N) (later (cons) (* N N)))

to each of the numbers. This function in turn returns the result of
'later'.

So the key here is 'later'. As the reference says,

   (later 'var . prg) - var

'later' accepts a 'var' (i.e. a symbol or a list cell), and returns that
var. As a side effect, it takes a program (a 'prg' which is a list of
expressions), runs that in a child process, and stores the result of
that 'prog' in the 'var' at some later point when the child process is
done.

For a simple example, we can execute in the REPL

   : (later 'A (+ 1 2 3 4 5))
   - A

We see that 'later' returs the variable 'A'. But if we look a moment
after that into the value of 'A'

   : A
   - 15

we see that it has received the result of the calculation.


A single call to 'later' is not very useful, because we might instead
directly execute the expression.

But if one same expression has to be done in parallel (a typical use
case is starting a parallel database query on remote machines), then we
pass list cells instead of a single variable to 'later'.

This is done with the 'mapcan' and 'cons' above. Remember that (cons) is
just a shortcut of (cons NIL NIL), and that 'mapcan' concatenates the
returned results. Thus, the above call without 'later' gives:

   : (mapcan '((N) (cons NIL NIL)) (1 2 3 4))
   - (NIL NIL NIL NIL)

However, if we have

   (mapcan '((N) (later (cons) (* N N))) (1 2 3 4))

Then as a side effect each call to 'later' receives its private, newly
'cons'ed list cell - i.e. a 'var' - which it duefully retunrs to
'mapcan' to be concatenated to the full list.

At the same time, each 'later' remembers its private cell, and stores
its result from the child process there.

Then 'wait' waits until ALL cells are filled (i.e. non-NIL).



 Another confusing thing is the @. How does one find which of the
 previous functions updated the @, and which did not. I know that control

This is documented in http://software-lab.de/doc/ref.html;. Exclusively
the (flow) functions listed there will modify '@'.

There's also a nice article by Thorsten: The many uses of @ in PicoLisp

   http://picolisp.com/wiki/?atmark

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


Re: Build transient value on the fly

2014-07-28 Thread Tomas Hlavaty
Hi Christophe,

 No problem for Display, but hello should spontaneously have its value
 changed to some XML containing the string hello.

 in other words, you want to use the transient symbol hello as a
 variable?  What is preventing you?

 The problem is that I would like to avoid maintaining a list of
 all transient that will be used. The idea was to automatically,
 or spontaneously, transform the value of _any_ transient
 using its name as a base.
 This would allow programs written in an embedded domain-specific
 language to be exported with different formats, considering
 that this embedded language would be reprogrammed.
 And transient symbols too.

I can't make sense of what you are trying to achieve.  Why do you want
to use transient symbols?  Why not use normal interned symbols?  How
does your use case differ?  Do you have a simple example?

Cheers,

Tomas
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Differences in mapping functions

2014-07-28 Thread S Pico
Hi Alex

Thanks for your prompt reply...I am adding my replies inline..    

Srini


 From: Alexander Burger a...@software-lab.de
 To: picolisp@software-lab.de 
 Sent: Monday, July 28, 2014 1:50:28 PM
 Subject: Re: Differences in mapping functions


...

  I am often confused between the variants of the map functions: map,
  mapc, mapcar, mapcan, mapcon, maplist.

 Yes, indeed. The names of these 6 functions are historic, they are in
 most Lisp variants since early on.

Thanks, this was good to know, as I was then able to find some Lisp sites with 
additional documentation/examples on these functions.

...

 In general, all functions in the Only CAR column above can be replaced
 by the Whole list functions if the argument function takes car of
 applying 'car' to the argument list.

Another difference is that the mapcon and mapcan functions must supply a 
function that returns a list, while the others can supply a function that 
returns an atom?

 I hope this clears things up a little.
Yes, thanks again..

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


Re: Differences in mapping functions

2014-07-28 Thread Thorsten Jolitz
Alexander Burger a...@software-lab.de writes:

Hi Alex,

 I am often confused between the variants of the map functions: map,
 mapc, mapcar, mapcan, mapcon, maplist.

 Yes, indeed. The names of these 6 functions are historic, they are in
 most Lisp variants since early on.

[...]

 I hope this clears things up a little.

Thanks for this nice and short explanation, I'm sure I will use this
post as a reference in the future. 

I would even say that it would make a perfect wiki article!

,
| Mapping functions in PicoLisp 
`

or so 

-- 
cheers,
Thorsten

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


Re: Differences in mapping functions

2014-07-28 Thread Amaury Hernández Águila
I agree. I'm constantly reading the reference of any lisp when dealing with
maps, and their descriptions are usually vague. When prototyping I always
ignore mapcon and mapcan because I always forget their difference (and
because of their destructive nature, which isn't considered functional).
El jul 28, 2014 1:11 PM, Thorsten Jolitz tjol...@gmail.com escribió:

 Alexander Burger a...@software-lab.de writes:

 Hi Alex,

  I am often confused between the variants of the map functions: map,
  mapc, mapcar, mapcan, mapcon, maplist.
 
  Yes, indeed. The names of these 6 functions are historic, they are in
  most Lisp variants since early on.

 [...]

  I hope this clears things up a little.

 Thanks for this nice and short explanation, I'm sure I will use this
 post as a reference in the future.

 I would even say that it would make a perfect wiki article!

 ,
 | Mapping functions in PicoLisp
 `

 or so 

 --
 cheers,
 Thorsten

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



Re: Differences in mapping functions

2014-07-28 Thread S Pico


Hi Alex

The diagram you produced makes a very nice and succinct reference...

                   Whole list     Only CAR
      --+-+---
      No result |     map     |    mapc
                |             |
      append    |    maplist  |   mapcar
                |             |
      concat    |    mapcon   |   mapcan

Thanks again
Srini

- Original Message -
 From: Thorsten Jolitz tjol...@gmail.com
 To: picolisp@software-lab.de
 Sent: Monday, July 28, 2014 4:03:59 PM

 Alexander Burger a...@software-lab.de writes:

 I am often confused between the variants of the map functions: map,
 mapc, mapcar, mapcan, mapcon, maplist.

 Yes, indeed. The names of these 6 functions are historic, they are in
 most Lisp variants since early on.


[...]

 I hope this clears things up a little.

 Thanks for this nice and short explanation, I'm sure I will use this
 post as a reference in the future. 

[Srini] Yes, for me also...


 -- 
 cheers,
 Thorsten

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

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


Re: Understanding the later function

2014-07-28 Thread S Pico




Hi Alex,

Thanks for the detailed reply. Pl. see my reply inline..

Srini



- Original Message -
 From: Alexander Burger a...@software-lab.de
 To: picolisp@software-lab.de
 Sent: Monday, July 28, 2014 2:21:53 PM


  I am trying to understand this example from the reference:
  (prog1  # Parallel background calculation of square numbers
     (mapcan '((N) (later (cons) (* N N))) (1 2 3 4))
     (wait NIL (full @)) )

 Could you please explain how it works, because it has many
 interrelated pieces: cons,mapcan, wait that I thought I understood
 individually but still I do not understand the example.

...

 'later' accepts a 'var' (i.e. a symbol or a list cell), and returns that
 var. As a side effect, it takes a program (a 'prg' which is a list of
 expressions), runs that in a child process, and stores the result of
 that 'prog' in the 'var' at some later point when the child process is
 done.

Somehow, this made it clear for me, although when I read the reference now, it 
essentially said the same thing more concisely.

 This is done with the 'mapcan' and 'cons' above. Remember that (cons) is
 just a shortcut of (cons NIL NIL), and that 'mapcan' concatenates the
 returned results. Thus, the above call without 'later' gives:
   : (mapcan '((N) (cons NIL NIL)) (1 2 3 4))
   - (NIL NIL NIL NIL)

This was useful as I did not realize (though it is so clear now) that 
 (cons) = (cons NIL) = (cons NIL NIL)
  i.e produces a single cell with NIL in CAR and in CDR.

 However, if we have
   (mapcan '((N) (later (cons) (* N N))) (1 2 3 4))
 Then as a side effect each call to 'later' receives its private, newly
 'cons'ed list cell - i.e. a 'var' - which it duefully retunrs to
 'mapcan' to be concatenated to the full list.

Yes, understand now...


  Another confusing thing is the @ How does one find which of the
  previous functions updated the @, and which did not. I know that control

 This is documented in http://software-lab.de/doc/ref.html;. Exclusively
 the (flow) functions listed there will modify '@'.
 There's also a nice article by Thorsten: The many uses of @ in PicoLisp
  http://picolisp.com/wiki/?atmark

I read both of these references before, but am struggling to apply. From the 
first one:
    Functions with controlling expressions are case, casq, prog1, prog2,
    and the bodies of *Run tasks. 
    Functions with conditional expressions are and, cond, do, for, if, if2, 
ifn, loop, nand, nond,     nor, not, or, state, unless, until, when and while. 

So probably @ is updated by the function later (body of run tasks). Another 
possibility is 
that prog1 that updates the @ with NIL NIL NIL NIL (the result of the first 
expression), but this is not likely, I think, as the @ would only be updated 
by it after the wait completes as well.


 ♪♫ Alex

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

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


Re: Build transient value on the fly

2014-07-28 Thread Christophe Gragnic
On Mon, Jul 28, 2014 at 9:11 PM, Tomas Hlavaty t...@logand.com wrote:

 I can't make sense of what you are trying to achieve.  Why do you want
 to use transient symbols?  Why not use normal interned symbols?  How
 does your use case differ?  Do you have a simple example?

Suppose you embed a DSL in Picolisp, like this:
(de Afficher (msg)
   (println msg))
Where «Afficher» is the French for «Display».
Now here is a simple program:
(Afficher Hello!)
When run it with the definition above, the message Hello! is displayed.

Now I want to export the program to XML to build a blocks configuration
for Blockly. An example built (then tweaked by hand) with:
https://blockly-demo.appspot.com/static/apps/code/index.html
block type=Afficher
  value name=TEXT
block type=text
  field name=TEXTHello!/field
/block
  /value
/block

Consider that Afficher is not the only command of the language.
There is a kind of «concatenate», a «read»…
The Lisp syntax is marvellous because the data I need to translate (the
program) is also source code (well, it was since the beginning!).
All I need is to reprogram my DSL like this:
(de Afficher (msg)
   (pack
 block type=\Afficher\value name=\TEXT\
 msg
 /value/block))

But I need transient symbols to spontaneously have the value:
block type=textfield name=TEXT*/field/block
Where * is the name of the transient symbol.
I could assign each transient the right value, but a bit of magic
would save time.

Is it better?


chri

-- 

http://profgra.org/lycee/ (site pro)
http://delicious.com/profgraorg (liens, favoris)
https://twitter.com/profgraorg
http://microalg.info
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Differences in mapping functions

2014-07-28 Thread Alexander Burger
Hi Srini,

 Another difference is that the mapcon and mapcan functions must supply
 a function that returns a list, while the others can supply a function
 that returns an atom?

Not exactly. 'mapcon' and 'mapcan' can return any s-expression. These
results are then concatenated just as 'conc' does, and they may well be
atoms (most importantly, they can be NIL). This corresponds to

   : (conc (1) 2 (3 4) 5 (6))
   - (1 3 4 6)

while 'maplist' and 'mapcar' build a list from the results, just as
'list' does:

   : (list (1) 2 (3 4) 5 (6))
   - ((1) 2 (3 4) 5 (6))

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