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

#1
Anything else we might add? / and to set $it?
July 12, 2017, 08:10:02 AM
Many lisps are taking over clojure's threading macros in some shape. Picolisp has a special variable @ that holds the result of the last computation of some functions (like newlisp's $it). and is one of them and it enables it to use it for threading. Would something like this be welcomed in newlisp?

(filter (fn (x) (> x 10))
        (map inc '(1 2 3 4)))

could then be written as

(and (map inc '(1 2 3 4))
     (filter (fn (x) (> x 10)) $it))

or even

(and '(1 2 3 4)
     (map inc $it)
     (filter (fn (x) (> x 10)) $it))
#2
Yeah, I just felt a bit of redundancy, ! is synchronous which means it calls fork, exec and wait (or something similar, not sure how system is coded exactly). Then we call another fork and wait. But as you said process could solve this, although that requires a command-string which means I either have to go {sh -c "..."} or find my executable (e.g. git) with an exec which first. I would probably prefer having access to execlp directly in some cases :)



Anyway, thank you for your help, my script works flawlessly now ;)
#3
Yes, that pretty much does it, thanks! As a nitpick - is there no way to wait-pid for something that is forked only once? Looking at the sources ! uses system which is a fork+exec sh -c and you need to wrap that in another fork to get the pid. And why is the exit code shifted?
#4
There are some minor inconsistencies in the docs, namely:



[*]the Cilk API part here http://www.newlisp.org/downloads/newlisp_manual.html#cilk">http://www.newlisp.org/downloads/newlis ... .html#cilk">http://www.newlisp.org/downloads/newlisp_manual.html#cilk says the commands are available on windows, whereas each function (spawn, sync and abort) state "The function {func} is not available on Windows". So which one is true? :)


  • [*]the first example here http://www.newlisp.org/CodePatterns.html#toc-15">http://www.newlisp.org/CodePatterns.html#toc-15 has some weird output shown.
    (exec "ls *.c") → ("." ".." "util.c" "example.ls")
  • [/list]


    I would fix the docs myself if I knew where to do it and if it's publicly editable, or open to PRs/patches.



    One more off topic question - is there a place newlispers hang out? The IRC channel seems pretty empty and I can't find anything else.
    #5
    Anything else we might add? / shell-like scripting
    July 11, 2017, 12:02:44 AM
    Looking at http://www.newlisp.org/downloads/newlisp_manual.html#processes">http://www.newlisp.org/downloads/newlis ... #processes">http://www.newlisp.org/downloads/newlisp_manual.html#processes I see there are several ways to start an external process, namely !, exec, process and spawn. So I thought let's write my typical toy tool - parallel git pull. It's a simple script that gets a set of root folders, looks for subfolders that are git projects and runs a git pull inside them. This should run in parallel since most of the time is spent on waiting for the network. The output to the console should be updated live and each line should be a simple "{project-folder} finished pulling with exit code {exit-code}".



    So I need the bash equivalent of something like "git pull &>/dev/null; exitCode=$?", i.e. suppress all output and fetch the exit code. I see a combination of process, exec+which and wait-pid can do this job.



    Having this explained my question is - can I retrieve this output live from subprocesses with the Cilk API without resorting to send/receive? I see that the result of a subprocess is stored in the symbol one gives to spawn but I don't see a reasonable way to fetch that information using sync. Am I missing something?