Re: PicoLisp is DEAD (Was: PicoLisp and its (lack of) libraries)

2012-01-24 Thread Doug Snead
After many merry rounds of compilation and discovery, it seems that the 
ndk-build's compiler -falign-functions[=n] and friends align functions relative 
to this option, but off by one (+1, or is that just |1?).;-)

In pico.h, sadly, I besmirched the code thusly,

#ifdef ANDROID_ARM
// android arm seems to have weird off-by-one alignment
#define FUNCT2LISP_ALIGN(f) ((f)-1) // hopefully optimise to 
#define LISP2FUNCT_ALIGN(f) ((f)+1) // a single  inc  ...
#else
#define FUNCT2LISP_ALIGN(f) (f)
#define LISP2FUNCT_ALIGN(f) (f)
#endif

#define evSubr(f,x) (*(fun)( LISP2FUNCT_ALIGN( num(f) )  ~2 ) )(x)

so in boxSubr in main.c, 

   if (num(FUNCT2LISP_ALIGN(f))  3)
  giveup(Unaligned Function);
   return (any)(num(FUNCT2LISP_ALIGN(f)) | 2);

(Er, I bet I missed some places, need to check.)

And then to talk with java I used the miniPicoLisp string-based library mods 
mentioned earlier, with a little jni C glue to hold it together. 

Cheers,

Doug


--- On Mon, 1/23/12, Jakob Eriksson ja...@aurorasystems.eu wrote:

 From: Jakob Eriksson ja...@aurorasystems.eu
 Subject: Re: PicoLisp is DEAD (Was: PicoLisp and its (lack of) libraries)
 To: picolisp@software-lab.de
 Date: Monday, January 23, 2012, 11:47 PM
 
 
 On January 24, 2012 at 7:49 AM Doug Snead semaphore_2...@yahoo.com
 wrote:
 
 
  I have a (slightly hacked) version of miniPicoLisp
 running as an android
  native library as a proof of concept.  No no
 additional java interpretation
  penalty.
  
  
 Wow, this is interesting!
  
  
 
  My thought is that now I have a new tool - a way to
 make picolisp and pilog
  (prolog) work in android, but will do the UI in java
 like most android apps.
  
  
 That is how I plan to use (mini)PicoLisp in my program too.
  
  
  
 
  But miniPicoLisp is pure, and easier to port.
  
 Indeed, and for me the most interesting right now.
  
 best regards,
 Jakob
  
 --
 UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

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


Re: PicoLisp is DEAD (Was: PicoLisp and its (lack of) libraries)

2012-01-24 Thread Alexander Burger
Hi Doug,

 After many merry rounds of compilation and discovery, it seems that
 the ndk-build's compiler -falign-functions[=n] and friends align
 functions relative to this option, but off by one (+1, or is that just
 |1?).;-)

Weird indeed. Can't believe ;-)


 In pico.h, sadly, I besmirched the code thusly,
 
 #ifdef ANDROID_ARM
 // android arm seems to have weird off-by-one alignment
 #define FUNCT2LISP_ALIGN(f) ((f)-1) // hopefully optimise to 
 #define LISP2FUNCT_ALIGN(f) ((f)+1) // a single  inc  ...
 #else
 #define FUNCT2LISP_ALIGN(f) (f)
 #define LISP2FUNCT_ALIGN(f) (f)
 #endif
 
 #define evSubr(f,x) (*(fun)( LISP2FUNCT_ALIGN( num(f) )  ~2 ) )(x)
 
 so in boxSubr in main.c, 
 
if (num(FUNCT2LISP_ALIGN(f))  3)
   giveup(Unaligned Function);
return (any)(num(FUNCT2LISP_ALIGN(f)) | 2);
 
 (Er, I bet I missed some places, need to check.)

Yes. Looks good. I would say taking care of boxSubr() and evSubr() are
enough.


Explanation for other readers: The bit fiddling is necessary because
MiniPicoLisp depends on having bit zero of a cell's CDR pointer free, to
use it as the GC mark bit.

In mini/doc/structures we see

  Primary data types:
 num  xx10
 ...

and

sym  sym
||
VV
  +-+-++-+-+
  |  |  | val || txt | val |
  +--+--+-++-+-+

'val' is assumed to _always_ have a zero in the least significant bit,
as this is used as the GC mark bit.

Decrementing the function pointer with FUNCT2LISP_ALIGN has that effect.
Without it, the first call to the garbage collector would crash the
interpreter, as all built-in functions would be dumped.

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


javac ImageNoise, file location

2012-01-24 Thread Jon Kleiser
Hi Alex,

I just tried your ImageNoise code, found here
http://rosettacode.org/wiki/Image_noise#PicoLisp. I may have tried it,
or some other javac sample code, earlier, as the following problem rang a
bell: With the ImageNoise script file in some other directory than the
picoLisp, where the ersatz and tmp are, then I get
ClassNotFoundException: ImageNoise; otherwise it works as intended. Is
it possible to modify the ImageNoise code so that the location of this
file is not so critical? If that is not easy, then I think it would be a
good idea to write a few words on this at the rosettacode.org/wiki.

/Jon

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


Re: javac ImageNoise, file location

2012-01-24 Thread Christian Kellermann
Hi Jon,

* Jon Kleiser jon.klei...@usit.uio.no [120124 21:14]:
 With the ImageNoise script file in some other directory than the
 picoLisp, where the ersatz and tmp are, then I get
 ClassNotFoundException: ImageNoise; otherwise it works as intended. Is
 it possible to modify the ImageNoise code so that the location of this
 file is not so critical? If that is not easy, then I think it would be a
 good idea to write a few words on this at the rosettacode.org/wiki.

Have you tried setting the classpath to also point to the picolisp
Ersatzlisp? Either the -classpath or the environment variable should
work. Other java apps have got the same problem and usually work
around it by some trampoline script.

Kind regards,

Christian

-- 
Who can (make) the muddy water (clear)? Let it be still, and it will
gradually become clear. Who can secure the condition of rest? Let
movement go on, and the condition of rest will gradually arise.
 -- Lao Tse. 
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Macros

2012-01-24 Thread Imran Rafique
Thanks for the detailed response Alex. Sorry for taking so long to
respond. Comments inline ...

On 23 January 2012 14:53, Alexander Burger a...@software-lab.de wrote:

  But one of the key things which make me feel comfortable in any lisp is the
  knowledge that I can effectively re-arrange the syntax of certain operation
  sequences to forms that I prefer.

 However, you can do that also in PicoLisp. The above doesn't mean that
 you can't programmatically manipulate your code. Basically, there are
 two possibilities:

 1. Use a read macro

   In a certain sense, the reader is the compiler of PicoLisp. Once an
   expression is read, it exists as an internal s-expression pointer-
   structure. If you use a read macro with '`' or '~', you can build any
   code structures you like.

   Example:

      (de foo (A B)
         `(build-some-code)
         ~(when (some-condition)
            (build-more-code) )
         ... )

   You might call that a micro-macro ;-)

 2. Use 'def' instead of 'de' for a completely evaluated definition

      (def 'foo
         (list (get-parameters)
            '(some static expression)
            (some calculated expression) ) )

   Quite often it is convenient to simply use 'curry' here.

 You can of course also combine these methods.


Interesting. When reading through the docs, it did occur to me at the
time that read-macros were the only place available in picolisp to
compute stuff, before runtime. But, I never saw how I could create my
own read-macro's. I went off looking for functions equivalent to
(set-read-syntax! ), etc ...

I totally missed what ` does (I guess I'm too used to it meaning
quasiquote in other lisps).

BTW, is it possible to create your own reader macro's?


  Once you get used to this feeling of *freedom*, its really hard to give it
  up. And honestly, I think this is one key lisp'ism which picolisp lacks