beneroth changed the topic of #picolisp to: PicoLisp language | The scalpel of software development | Channel Log: https://libera.irclog.whitequark.org/picolisp | Check www.picolisp.com for more information
pfd has joined #picolisp
aw- has quit [Remote host closed the connection]
aw- has joined #picolisp
pfd has quit [Ping timeout: 260 seconds]
rob_w has joined #picolisp
<Hunar> Hello abu, ix.io/4gIT run this and it starts counting, press ctrl-c it stops, enter (go) to start counting again. Why this time ctrl-c doesn't stop it like it did before?
<abu[m]> Ctrl-C sends a SIGINT. PicoLisp handles SIGINT in the default way (i.e. terminate) *before* a REPL is started, and breaks into a debug loop *after* a REPL runs
<abu[m]> So it depends in which env you start this code
<abu[m]> BTW, my recommendation for 'prog' yesterday was not good
<abu[m]> Better is (push '*Term '(on *End) '(prinl "stop"))
<abu[m]> or, best, (de *Term (on *End) (prinl "stop"))
<abu[m]> 'de' has the advantage that you can later do (vi '*Term) to inspect it etc.
<Hunar> I want the user to run my file (pil file.l) then a loop starts that calculates stuff, the user needs to change parameters midway through the calculation, so I want ctrl-c to break out of the loop, the user changes some variables, then restarts the function that starts the calculation.. this happens multiple times.
<Hunar> what should I do
<abu[m]> I would not mess with SIGINT. It is an *interrupt*, intended for debugging
<abu[m]> So breaking out of the loop is what is intended
<abu[m]> hmm,
<abu[m]> how to have a REPL first?
<abu[m]> We need a way so that the user starts it from the REPL, not directly from the shell
<Hunar> I liked the ctrl-c option :) it was natural. is there a hack to make it work?
<beneroth> how about other keyboard shortcuts?
<beneroth> maybe to do multiple kind of actions, vim style?
<beneroth> just as an idea
<Hunar> Any key would do
<beneroth> Ctrl+C is special
<abu[m]> I think other keys do not solve the problem
<beneroth> abu[m], maybe he could check for key presses in a coroutine parallel to the calculations?
<abu[m]> Ctrl-C is just mapped to SIGINT by stty
<abu[m]> The problem is SIGINT
<beneroth> not using a signal I mean
<beneroth> or do the calculations in a decidated child process and let the parent handle user interaction
<abu[m]> There are two ways to get a breakpoint: SIGINT and embedding '!'
<abu[m]> So you put '!' in your code, and use some signal to do (on *Dbg)
<abu[m]> '!' only stops if *Dbg is on
<beneroth> I don't think he really needs a breakpoint. He just needs a way to stop the ongoing calculation and allow interactive changing of variables
<abu[m]> ah, ok
<beneroth> breakpoint is a cheap way to do that, okay for programmer, but not really for software user
<Hunar> yes, pause->repl->run
<beneroth> so I think coroutine or child process could be a solution
<beneroth> it's a bit more involved, but allows a lot of flexibility and features
<abu[m]> Simply (key 40)
<abu[m]> if non-NIL, a key was pressed
<beneroth> yeah that's easy. the hard part is the task management so to say
<beneroth> maybe abu[m] you can point Hunar into a direction? should he look into coroutines, *Task mechanism, or child processes?
<abu[m]> better (key 0)
<beneroth> I guess any of this can solve this, but one way might be easier/more feasible than the others
<abu[m]> I think we don't need those here
<beneroth> oh okay
<beneroth> yeah you can also regularly check for key presses in the calculation loop
<abu[m]> At a proper place (when (key 0) (load))
<beneroth> right
<beneroth> gotta go :)
<beneroth> bbl
<abu[m]> T
<abu[m]> cu :)
<abu[m]> pb1n.de/?cc5cdc
<abu[m]> Instead of (key 10) use (key 1)
<Hunar> Looks great :) I'll try it later. I forgot how this works (printsp (inc (0)))
<abu[m]> (0) is a single cell, so it is a "var"
<abu[m]> (inc 'var)
<Hunar> 😕
<abu[m]> Not clear? ;)
<Hunar> My brain doesnt work
<abu[m]> (let N 0 ... (inc 'N) is the same
<abu[m]> pass a "var" to 'inc'
<abu[m]> well, to be exact, (zero N) ... (inc 'N)
<abu[m]> cause (0) is static in the code
<abu[m]> 'inc' takes either a number or a var
<abu[m]> (inc <num>) is the same as (+ 1 <num>)
<abu[m]> (inc 'var) is (setq var (+ 1 var))
<Hunar> Let me tell you where my head is stuck.. 0 is a number, (0) is a list, (inc (0)) will turn 0 into 1.. but isn't the list lost now?
<abu[m]> It is not lost, cause it is part of the code (statically)
<abu[m]> (de f () (inc (0)) (f) (pp 'f)
<abu[m]> like a "static int n;" in C
<Hunar> Ah, it modifies the code
<abu[m]> Not really the code, but data (here 0) embedded in the code
<abu[m]> code and data are the same
<abu[m]> The (0) is never executed, so I call it data and not code
<Hunar> I think I got it :)
<abu[m]> int f () { static int n; return ++n; }
<Hunar> one tiny question about loading data from files. if I have a list. should I save the list alone (1 2 3) or save this (setq data (1 2 3)) in the file? in the second case i just (load) it, is that the intended way in lisp?
<abu[m]> Both ways are useful. It depends what else is needed.
<Hunar> I just need to save and restore some variables
<abu[m]> There is also a third way
<abu[m]> (out "a" (printnl 'X X) ...
<abu[m]> (in "a" (while (read) (set @ (read]
<abu[m]> It depends on what should be easier, saving or loading
<abu[m]> for example 'dump' of a database produces a 'load'able format
<abu[m]> (dump) in @lib/too.l
<abu[m]> But usually producing a 'load'able format is too tedious
<abu[m]> 'dump' is used often, so it was worth the effort
<abu[m]> But for just saving and loading variables I would go with (println 'Var1 Var1 'Var2 Var2 ...
<Hunar> Thanks :)
<abu[m]> Perhaps look at 'rc'. It is intended for such purposes ("poor man's database)
<Hunar> :) looks good
rob_w has quit [Ping timeout: 260 seconds]
rob_w has joined #picolisp
rob_w has quit [Ping timeout: 260 seconds]
rob_w has joined #picolisp
rob_w has quit [Remote host closed the connection]
pfd has joined #picolisp
Regenaxer has quit [Ping timeout: 252 seconds]
chexum has quit [Remote host closed the connection]
chexum has joined #picolisp