Re: Build transient value on the fly

2014-08-15 Thread Christophe Gragnic
Dear list, some updates about my problem.

I eventually decided to do the things The Good Way.
Adding a shortcut to EmuLisp was a fun hack, almost a joke, but not a
good idea as:
1) It was not EmuLisp anymore.
2) I may need this export functionality with other platforms (read
PicoLisp implementations).
3) Above all, I need this functionality with numbers too.

Now what I do is preprocess the source code with this:

(de protect_literals (src)
   (cond
  ((num? src) (list 'Literal src))
  ((str? src) (list 'Literal src))
  ((sym? src) src)
  (T  (mapcar 'protect_literals src))
)
)

Then handle numbers and transients like this:

(de Literal (content)
  (cond
((num? content) (pack ""
  content
  ""))
((str? content) (pack ""
  content
  ""))
(T "Is this really a literal?")
  ))

Works for me.
I also wanted to post this to have a free review by better PicoLispers than me;)


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


Re: Build transient value on the fly

2014-07-29 Thread Christophe Gragnic
Le 29 juil. 2014 10:40,  a écrit :
>
> Why not redefine function Afficher?
> [...]
> Would that be an idea?

But this IS the idea I'm trying to explain!!!
The problem was to also redefine transient symbols, dynamically.

chri


Re: Build transient value on the fly

2014-07-29 Thread andreas
Why not redefine function Afficher?
Have one file in which Afficher has the original functionality, and
another file were it instead produces this bockly XML ?
Then you write your simple program in a third file, and depending on which
of the other two files you (load), it runs or it produces XML.

Would that be an idea?

> On Mon, Jul 28, 2014 at 9:11 PM, Tomas Hlavaty  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
> 
>   
> 
>   Hello!
> 
>   
> 
>
> 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
>  ""
>  msg
>  ""))
>
> But I need transient symbols to spontaneously have the value:
> *
> 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
>



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

  

  Hello!

  


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
 ""
 msg
 ""))

But I need transient symbols to spontaneously have the value:
*
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: 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: Build transient value on the fly

2014-07-28 Thread Christophe Gragnic
On Mon, Jul 28, 2014 at 9:27 AM, Tomas Hlavaty  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


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" "hello"
   (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-27 Thread Christophe Gragnic
On Sun, Jul 27, 2014 at 3:09 PM, Tomas Hlavaty  wrote:
> Hi Christophe,

Hi. As I tried to explain in this sentence:

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

I had no problem with functions (I used a simple «de»).
The real problem is with transient symbols. Or maybe I missed something?
Thanks for trying to help.


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: Build transient value on the fly

2014-07-27 Thread Tomas Hlavaty
Hi Christophe,

> If I sum up (efficiently) my problem, I need a program like:
>
> (Display "hello")
>
> to have two interpretations.
> In the first context it would (surprise surprise) «println "hello"».
> In the second context it should be reprogramed to generate some XML.
> No problem for Display, but "hello" should spontaneously have its value
> changed to some XML containing the string "hello".

picolisp has dynamic bindings so what you want is trivial:

1st case:

(let Display println
   (Display "hello") )

2nd case:

(let Display (Msg (prinl "" Msg ""))
   (Display "hello") )

Another, more traditional approach is using methods, which would
dispatch on some kind of context:

(de display (Msg)
   (display> *Ctx Msg) )

(class +Case1 ...)

(dm display> (Msg)
   (println Msg) )

(class +Case2 ...)

(dm display> (Msg)
   (prinl "" Msg "") )

(display (new +Case1) "hello")
(display (new +Case2) "hello")

Hope it helps,

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


Re: Build transient value on the fly

2014-07-27 Thread Christophe Gragnic
On Sun, Jul 27, 2014 at 8:05 AM, Alexander Burger  wrote:
> Hi Christophe,

Hi.

> Thinking about it (again), it occurs to me that this description in some
> way matches the behavior of _external_ symbols. These also may change
> their value (and properties) «spontaneously».
>
> Perhaps you can take a look at how external symbols are handled by the
> interpreter when they are accessed.

If I sum up (efficiently) my problem, I need a program like:

(Display "hello")

to have two interpretations.
In the first context it would (surprise surprise) «println "hello"».
In the second context it should be reprogramed to generate some XML.
No problem for Display, but "hello" should spontaneously have its value
changed to some XML containing the string "hello".

So external symbols won't help me here.
Thanks again anyway. I managed to do what I wanted in EmuLisp:
https://github.com/Grahack/EmuLisp/commit/3074425789496e49f352d6b6640ef8048316dd62
which is the only platform I need this trick implemented on for now.

Thinking about this a bit harder, I may need it on the other platforms
(original PicoLisp and Ersatz), since it is a great way to export
programs to HTML for instance. Maybe I won't need transient to
generate something else than themselves though.


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: Build transient value on the fly

2014-07-26 Thread Alexander Burger
Hi Christophe,

> > Hmm, so is this the same as the localization does in PicoLisp?
> 
> Quite the same, except that we don't have a list of all messages to
> translate. Any transient, even an unexpected one, should
> «spontaneously» have its value transformed by a function
> when retrieved.

Thinking about it (again), it occurs to me that this description in some
way matches the behavior of _external_ symbols. These also may change
their value (and properties) «spontaneously».

Perhaps you can take a look at how external symbols are handled by the
interpreter when they are accessed.

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


Re: Build transient value on the fly

2014-07-25 Thread Christophe Gragnic
On Fri, Jul 25, 2014 at 4:53 PM, Alexander Burger  wrote:
> I see. This is not possible, because the fetching of a symbol's value
> happens at the very lowest level of the interpreter (in fact it is only
> a single machine instruction), and can't be changed from the outside.
> And if you'd change this, it would slow down everything quite a lot, as
> each value fetch would need to do some runtime check.
>
> There must be a better way. Can't you write an access function, which
> inspects the symbol and takes appropriate action?

I could do that but this would clutter the code. And this won't work for
top-level naked strings, except if I test them also from the outside, which
would complicate things again.
As I only need this in the JS version, I'll hack (my version of)
EmuLisp gracefully !

> I have never seen something like that in other languages. There a string
> is always a primitive type, distinct from a (Lisp) symbol.

Great. Nice. This is what I wanted to know.
Thanks for your time.


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: Build transient value on the fly

2014-07-25 Thread Alexander Burger
Hi Christophe,

> > Hmm, so is this the same as the localization does in PicoLisp?
> 
> Quite the same, except that we don't have a list of all messages to
> translate. Any transient, even an unexpected one, should
> «spontaneously» have its value transformed by a function
> when retrieved.

I see. This is not possible, because the fetching of a symbol's value
happens at the very lowest level of the interpreter (in fact it is only
a single machine instruction), and can't be changed from the outside.
And if you'd change this, it would slow down everything quite a lot, as
each value fetch would need to do some runtime check.

There must be a better way. Can't you write an access function, which
inspects the symbol and takes appropriate action?



> > Transient symbols are just normal symbols, except that they have a
> > file-local scope, and happen to look lexically like strings in other
> > languages. That's all.
> 
> My question was about «look lexically like strings in other languages».
> Do some other Lisp have this king of mechanism?

I have never seen something like that in other languages. There a string
is always a primitive type, distinct from a (Lisp) symbol.

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


Re: Build transient value on the fly

2014-07-25 Thread Christophe Gragnic
On Fri, Jul 25, 2014 at 12:00 PM, Alexander Burger  wrote:
> Hi Christophe,

Hi Alex.

> Hmm, so is this the same as the localization does in PicoLisp?

Quite the same, except that we don't have a list of all messages to
translate. Any transient, even an unexpected one, should
«spontaneously» have its value transformed by a function
when retrieved.

>> I note that this transient thing is VERY powerful. Alex, could you
>> provide us with some historical hindsight about transient syms? Do
>> they exist in other languages? Are they your brainchildren?
>
> Transient symbols are just normal symbols, except that they have a
> file-local scope, and happen to look lexically like strings in other
> languages. That's all.

My question was about «look lexically like strings in other languages».
Do some other Lisp have this king of mechanism?


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: Build transient value on the fly

2014-07-25 Thread Alexander Burger
Hi Christophe,

> Is it possible to shortcut the value resolution of transient
> symbols with a custom function? Something like:

I'm not sure I understand the question.

The value of symbols (not only transients) is the CDR of the cell
representing the symbol. The evaluator of the interpreter fetches this
value, i.e. a single pointer-indirection.


> (de shortcut_transient (name)
>   (pack name "!"))
> This would add a "!" to the default value of a transient sym.

So something like

   (set MyTransient (pack "!" (val '"MyTransient")))

would do? Full example:

: (setq MyTransient "abc")
-> "abc"

: (set MyTransient (pack "!" (val '"MyTransient")))
-> "!MyTransient"

: MyTransient
-> "abc"

: (val @)
-> "!MyTransient"


Or, for a more general usage, you might consider using methods on
objects to achieve a more configurable, flexible behavior.



> BTW I had a related question (maybe for many months!):
> Is there a PicoLisp function/mechanism like «unknown» in Tcl:
> http://wiki.tcl.tk/795

You could 'catch' such errors

   (catch '("Undefined")
  ... )

but this is not completely the same.

A built-in handler for undefined functions exists, but only if the
symbol name contains a colon, e.g. 'lib:foo', then the interpreter looks
for a shared library 'lib' and there for a symbol 'foo'.



> Some context for the reason I need this kind of transient
> manipulation (for the curious and because maybe I'm trying
> to solve the wrong problem):
> I'm embedding a language in Picolisp. I managed to build
> Blockly blocks for this language:
> http://microalg.info/ide.html (click on «Commandes»,

Nice! :)


> For this I need to produce XML from Lisp code. This is quite
> easy considering that the data is not data but some source code.
> The trick is to reprogram my language so that each command
> will output some XML recursively (thanks to Lisp!!!).
> ...
> And more generally (and this is the problem I post about), I need
> "any transient sym" to dynamically have the value  (based on its name):

Hmm, so is this the same as the localization does in PicoLisp? Transient
symbols representing strings in the application are kept in a global
structure '*Uni', and are assigned a new value (i.e. the translation in
the target language) by the 'locale' function.



> I note that this transient thing is VERY powerful. Alex, could you
> provide us with some historical hindsight about transient syms? Do
> they exist in other languages? Are they your brainchildren?

Transient symbols are just normal symbols, except that they have a
file-local scope, and happen to look lexically like strings in other
languages. That's all.

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


Build transient value on the fly

2014-07-25 Thread Christophe Gragnic
Hi,

The technical/dry question:
Is it possible to shortcut the value resolution of transient
symbols with a custom function? Something like:
(de shortcut_transient (name)
  (pack name "!"))
This would add a "!" to the default value of a transient sym.
If I had to answer, I'd say «no», but PicoLisp is full of surprises!
I will need this functionnality in EmuLisp anyway so I'll
implement this. Any suggestion for a syntax/interface will be
appreciated.

BTW I had a related question (maybe for many months!):
Is there a PicoLisp function/mechanism like «unknown» in Tcl:
http://wiki.tcl.tk/795
(I'm a big fan of Tcl!!!)

Some context for the reason I need this kind of transient
manipulation (for the curious and because maybe I'm trying
to solve the wrong problem):
I'm embedding a language in Picolisp. I managed to build
Blockly blocks for this language:
http://microalg.info/ide.html (click on «Commandes»,
arrange blocks and see the generated code below).
This means I built the blocks and a generator that builds Lisp
programs from blocks configurations.
(for those who don't know Blockly:
https://blockly-demo.appspot.com/static/apps/index.html
https://code.google.com/p/blockly
)
I'm currently trying to do the converse operation:
build blocks configurations from Lisp programs.
(some docs and a live example
https://code.google.com/p/blockly
/wiki/Installation#Importing_and_Exporting_Blocks
See the XML tab here, after having built a program:
https://blockly-demo.appspot.com/static/apps/code/index.html
)
For this I need to produce XML from Lisp code. This is quite
easy considering that the data is not data but some source code.
The trick is to reprogram my language so that each command
will output some XML recursively (thanks to Lisp!!!).
I was quite happy to have this idea last night before sleeping, but
faced the transient problem in front of the screen this morning:
what about transient syms?

One example program: (Display "Hello world!")

This should translate to:

  

  Hello world!

  


I reprogram the Display command like this:
(de Display (content)
  (pack ""
content
""))

But I need "Hello world!" to have the value:

  Hello world!


And more generally (and this is the problem I post about), I need
"any transient sym" to dynamically have the value  (based on its name):

  any transient sym


I note that this transient thing is VERY powerful. Alex, could you
provide us with some historical hindsight about transient syms? Do
they exist in other languages? Are they your brainchildren?


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