Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - rrq

#226
Now I ran into a wall trying to use FOOP, or possibly it's really a bug. Namely that it appears arguments get copied in some funny way.... I've isolated my problem to this small example code:
(context 'One)
(define (One:One v) (list (context) v))
(define (put v) (setf (self 1) v))

(context 'Two)
(define (Two:Two one x)
  (:put one x) ;---------------------- mark 1
  (list (context) one x))

(context MAIN)
(constant 'uno (One 1))
(constant 'duo (Two uno 2)) ;----- mark 2

(println "uno=" uno)
(println "duo=" duo)

Thus, there are two contexts: One and Two, where in particular the Two "objects" are supposedly tied to One "objects" on "construction". Both of them also hold an auxillary value, and when a Two object is created, its auxillary value is propagated  to its One object.



But in the example, the One object passed in to the Two construction (at mark 2 in the code) is not the same as the One object it operates on in its constructor (at mark 1 in the code), and yet only a single One object has been created!

I get the following output:
uno=(One 1)
duo=(Two (One 2) 2)

This is with "newLISP v.10.6.0 32-bit on Linux IPv4/6 UTF-8 libffi"



I really hope someone can enlighten me about what is going on here, because it kind of is a show stopper for me.
#227
Not sure how much effort it takes, but I'd check out using "curses".

Done before:

http://www.newlispfanclub.alh.net/forum/viewtopic.php?f=12&t=240&hilit=curses">//http://www.newlispfanclub.alh.net/forum/viewtopic.php?f=12&t=240&hilit=curses
#228
Anything else we might add? / flat enough?
June 22, 2014, 04:32:36 AM
I just ran into this pebble on the beach, that the "flat" function doesn't flatten quoted sub lists.
> (flat '('(1 2) (3 4)))
('(1 2) 3 4)

Perhaps it's worth mentioning it in the doc, or fix it, if it's a mistake. By my inuition, the flat function should traverse into quoted lists the way it traverses into lambda expressions.
#229
What about:
(define (extend-env:filter) (cons 'extend-env:filter (args))
or, if you don't want its arguments to be evaluated:
(define-macro (extend-env:filter) (cons 'extend-env:filter (args))
#230
How about net-select?

http://www.newlisp.org/downloads/newlisp_manual.html#net-select">//http://www.newlisp.org/downloads/newlisp_manual.html#net-select

It's documented to deal with sockets, but at least on linux this means file descriptors in general (implemented at nl-sock.c#p_netSelect).
(net-select (list fd1 fd2) "read" -1)
This doesn't beat the pleasure of attaching C code of your own, but it does seem to offer the functionality.
#231
newLISP newS / Re: Embed C or ASM in newLISP
June 14, 2014, 06:31:01 AM
Right. My apologies.
#232
newLISP newS / Re: Embed C or ASM in newLISP
June 14, 2014, 04:34:23 AM
You need to make it into "shared libraries", then run newlisp with LD_LIBRARY_PATH set up, then declare the imported functions with (import ...), then Bob's your uncle.

It's amazingly simple (until you come to the data sharing)

Maybe this is a help

http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html">//http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html
#233
I might be in too deep surf here, but since noone else has ventured an answer yet, I'll give it a go... maybe it'll be of help to you.



Notably, the "(address x)" function puts its argument into a CELL_LONG type cell, whose contents field holds the incoming value. Thus, if your C function gets that long value, you can type cast it to (CELL*) in the hope of then having a pointer to the originating cell. This however, I believe, requires your newlisp level code to make sure the cell is not reclaimed by garbage collection, as otherwise it'll cause grief.
#234
A little bit later, I realized I could wrap the "process" into a fork, and there close "myout" before spawning the sub process. Thusly wrapped:
(fork (begin (close myout) (process ...)))
It kind of validates my theory that "myout" indeed is open for the sub process.



Perhaps it'd be sensible to revise the "process" method to in some way allow that pipe end closing to happen? Maybe even that the implementation could actually close all open file descriptors except the given ones on the execing-fork before exec-ing (that's me making assumptions about the implementation without having more than peeped at it :-))?
#235
I have difficulty in closing stdin for a sub process using (process ..).

The code snippet is:
; Spawn a reader for emptying sub process stdout as my stdout
(setq buffer nil)
(map set '(myin subout) (pipe))
(fork (begin (close subout) (while (read myin buffer 1000) (print buffer))))
(close myin)

(map set '(subin myout) (pipe))
(process "./myscript.zsh " subin subout)
(close subin)(close subout)
...
(close myout)

I would like that last "close" to close the stdin for the myscript.zsh sub process, but this doesn't seem to happen.



Possibly the issue is that the process spawned by the "process" function actually has inherited a writing end of the pipe (it's "dup" of "myout"), and that remains open. If so, how do I close it? Or have I missed something?
#236
I just ran into the following quirk. Basically, I wanted to include stack and memory limits in a script and therefore thought I could do it in the script header line, as:
!#/usr/bin/newlisp -s 4096 -m 100
but then I discovered that only the first of these options come into play.



Eventually  I learnt that the "optional arguments" for the script interpreter are actually passed in as a single first command line argument of the whole rest of line (this is on Linux), and newlisp happily and silently(!) takes an argument of '-s 4096 -m 100' to be the same as '-s4096'. Also, it appears that the handling and delivery of optional arguments may vary across platforms, so maybe one shouldn't use them at all.



But then, how do I make the script set its limits (and other options)? Do I have to have a separate wrapper shell script for its invocation?
#237
As I understand it from having browsed the code, a list is represented in a succession of CELLs where the "contents" fields point to the list members. Thus, a list like (1 2) of two elements would be represented by 4 CELLs, two of which are  list cells and two are integer cells. The Head (aka contents) of the first list cell points to the CELL holding integer 1, and the Tail of it (aka next) points to the second list cell. Likewise, the second list cell points to the 2 cell and the nil cell (which has a special cell type).

And as an implementation level side  note, the "aux" field of a list cell is used as a short-cut that generally points to the last element of the list (or nil or true).
#238
Great. Thanks. I suppose mostly it tells me that no sane person should venture into this even if they can make a good argument for having it :-)

Fair enough; and indeed, the newlisp as is, sure is a pleasure to work with anyhow.
#239
Is there a possibility of a function that lets me pivot the execution, in the way of saving the current environment (i.e., stacks etc) into a pdl of such, then pop and continue with a saved environment?

Thus, I imagine a function, say (pivot store), that firstly makes a blob (copy) of the current exection state, then pushes that onto the given "store" (list of blobs) or, if nil, onto an internal store, then pops a blob from the internal store, before restoring this as execution state, which thus continues. (Of course, the continuation should be as an immediate return from that other call of "pivot", rather than pushing the blob again)

That kind of primitive would open the gate for cooperative multi-tasking, and allow programs with thousands of light-weight "virutally concurrent" pursuits, such as large scale simulations, as well as other domains where "parallel pursuits" design is desired.

I've started with the coding, but I'm not fully on top of the extent of things to include in the execution state blob, and wanted to check here for pointers and thoughts first.
#240
Very recently I stumbled onto the newlisp site and got amazed by the excellent  practical sense in the approach; just the right things included for scripting, and yet a proper Lisp system. Hats off for the authors!



.. I had a question, but found answers by forum search, so removed it. Now this is just praise and no question :-)