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
razzy has joined #picolisp
<Regenaxer> razzy, the fzf call we tried yesterday is in fact very simple:
<Regenaxer> : (pipe (call "fzf") (line))
<Regenaxer> -> ("t" "i" "n" "y" "m" "c" "e" "/" "l" "a" "n" "g" "s" "/" "j" "p" "." "j" "s")
razzy has quit [Ping timeout: 252 seconds]
razzy has joined #picolisp
Hunar has joined #picolisp
<Hunar> Hi :) I think I found a bug ... In a pil terminal paste and run this (prin "a: ") (read) then type afew letters (like abc) now press backspace one by one everything is normal BUT when you delete the last letter, everything else in that line disappears .. It should only delete upto after the "a: "
<Regenaxer> Hmm, no idea. This is the readline() system library
<Regenaxer> I don't know if and how we can control this
<Regenaxer> readline() does not know that you modified the line
<Regenaxer> after you backspace over "abc" it thinks you deleted all it knows about, and clears the line
razzy has quit [Ping timeout: 265 seconds]
<Hunar> Hmm :/
<Regenaxer> you want to present some kind of prompt?
<Hunar> ێەس
<Hunar> Yes
<Hunar> sorry, keyboard wasn't switched
<Regenaxer> yeah
<Regenaxer> How about using *Prompt?
<Hunar> How to use it
<Regenaxer> Hmm, it does no help, same effect
<Regenaxer> (let *Prompt (prin "a :") (line))
<Hunar> :/
<Regenaxer> Wait
<Regenaxer> I did it wrong
<Regenaxer> (doc '*Prompt)
<Regenaxer> (setq *Prompt '("a"))
<Regenaxer> But *Prompt is used only in the REPL
<Regenaxer> perhaps not useful in your case
<Hunar> Yes, the workaround is using prinl
<Regenaxer> right
<Regenaxer> the -p ' ' option to bash read?
<Hunar> yes, says that read -e uses readline
<Regenaxer> and -p ?
<Hunar> I'm not sure if its a bash option or a readline option
<Hunar> read --help -p prompt output the string PROMPT without a trailing newline before attempting to read
<Regenaxer> readline is a C function
<Regenaxer> it is *used* by bash, python, clojure and everybody else
<Regenaxer> and bash probably sets it
<Regenaxer> the prompt
<Regenaxer> like pil21 does via *Prompt
<Regenaxer> but pil21 uses *Prompt only in the repl
<Regenaxer> so (setq *Promp ..) works
<Regenaxer> unfortunately only internally
<Regenaxer> not for calls like (line)
<Hunar> Hmm, I'll search for a little longer then giveup :)
<Regenaxer> cause in that case the repl itself does not prompt
<Regenaxer> you can call readline yourself via native
<Regenaxer> It takes the prompt as an argument
<Regenaxer> : (%@ "readline" 'S "a: ")
<Regenaxer> a: abc
<Regenaxer> -> "abc"
<Regenaxer> But this may have a memory leak
<Regenaxer> man readline
<Hunar> :/
<Hunar> Maybe (read) should take an optional prompt in the future :)
<Regenaxer> Not very useful
<Regenaxer> you don't want to (read) only
<Regenaxer> usually (line) etc
<Hunar> Right
<Regenaxer> and 'read' already has an optional arg
<Hunar> That reminded me of another question that i forgot :) what is the reason behind not having keyword arguments in pil
<Regenaxer> You can do this:
<Regenaxer> : (setq P (%@ "readline" 'P "a: "))
<Regenaxer> a: xyz
<Regenaxer> -> 489020231824
<Regenaxer> : (struct P 'S)
<Regenaxer> -> "xyz"
<Regenaxer> : (%@ "free" NIL P)
<Hunar> I have to study those to fully understand them :)
<Regenaxer> this is in a program:
<Regenaxer> : (let P (%@ "readline" 'P "a: ") (prog1 (struct P 'S) (%@ "free" NIL P)))
<Regenaxer> a: abc
<Regenaxer> -> "abc"
<Regenaxer> No big thing :)
<Regenaxer> "not having keyword arguments": What *are* keywords?
<Regenaxer> 'if' in C?
<Regenaxer> Lisp has no keywords, everything is a function
<Regenaxer> (let if car (if (1 2 3)))
<Regenaxer> ;)
<Regenaxer> So it depends on the dynamic context what 'if' means
<Hunar> I think the name is keyword parameters sorry ... when you call a function and specify the name of the parameter to be set for example in python print("hello", end="") this is to pass optional arguments but not following the order
<Regenaxer> There was a rosetta task
<Regenaxer> I forgot the details
<Regenaxer> you can make up your syntax
<Regenaxer> What would be your use case? I think there is always a better way in pil
<Regenaxer> Using variable number of arguments
Hunar has quit [Ping timeout: 256 seconds]
<Regenaxer> Found it, task "Named parameters"
Hunar has joined #picolisp
<Regenaxer> Hunar, I found the rosetta task
<Regenaxer> (foo '(Bar . 123) '(Mumble . "def"))
<Regenaxer> or
<Regenaxer> (foo '(Bar Mumble) 123 "def")
razzy has joined #picolisp
<Regenaxer> I think this is not elegant
<Regenaxer> razzy, did you see my note above?
razzy has quit [Ping timeout: 265 seconds]
<Regenaxer> Hmm
<Regenaxer> All ignored :(
<Hunar> The rosetta solution is cool, but not very clear for the programmer since you can't see what are the parameter names within (de No problem :) I haven't needed it yet.. I just wanted to know the reason behind it :) your point of view is interesting
<Regenaxer> I find it pretty useless
<Regenaxer> and *if* the interpreter would support it internally, it would be runtime overhead cause 99% it is not needed
<Hunar> I have a few questions to understand the native readline code above.. what does NIL do/mean in (%@ "free" NIL P) and what is 'P in (%@ "readline" 'P "a: ")
<Regenaxer> What *is* supported is destructuring bind now also for function args (not only 'let'), but only one level
<Regenaxer> NIL means to ignore the return value
<Regenaxer> 'P' is pointer return type
<Regenaxer> (%@ "readline" 'S "a: ") directly returns a string, but this would leak memory
<Regenaxer> (according to man readline)
<Hunar> Thanks :D I understand now
<Regenaxer> 'native' (and '%@') are really tough
<Regenaxer> because C has so many types and ways of calling
<Hunar> True
<Regenaxer> (doc 'native) explains it all, though terse
<Hunar> Does native work with c++ libraries :) or needs some glue code
<Regenaxer> I have to look it up too every time
<Regenaxer> I think it works, but you must call the internal name
<Regenaxer> as the linker sees it
<Regenaxer> I never had a use case
<Regenaxer> Perhaps beneroth knows more, he is C++ specialist ;)
<Hunar> I'll be waiting for beneroth's reply :)
<Regenaxer> :)
<Regenaxer> Do you have lib written in C++ ?
<Hunar> Not my own library, but It would be very useful for me to use https://eigen.tuxfamily.org/index.php?title=Main_Page which is "Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms."
<Hunar> when I see the word "C++ template" It usually means very complex and hard to work with outside c++ itself
<Regenaxer> yes, with different internal representations
<Regenaxer> As I understand it, do template generate the internal code
<Regenaxer> There is no longer a 1:1 relation between source and code
<Hunar> Its kina like macros
<Regenaxer> exactly
<Regenaxer> Same problem with macros in C
<beneroth> hi Regenaxer, Hunar
<Regenaxer> Cheers beneroth!
<beneroth> no expert in these parts.. but C++ libraries are usually made to work from C
<Regenaxer> Good thing then
<Regenaxer> Just needs docs or a man page
<Regenaxer> Usually a native call can easily be coded from a spec like in a man page
<beneroth> I love C++ templates. They very smart. But only needed for very specific stuff. Big canons. Many programmers use big canons when they should not, and then they wonder about the damage.
<Regenaxer> T
<beneroth> Regenaxer, I would say you want to get the header files of the library. that what you would include in another C/C++ program, which has all declarations of available functions, parameters, types
<Regenaxer> right, but sometimes more info is needed, like the readline() case where the caller must free() the memory
<beneroth> Templates: well classes in C++ are a generator for "struct" and struct-specific functions (methods). in the same way, C++ templates are a generator for C++ classes at compile time.
<beneroth> Regenaxer, T
<beneroth> this is a mess where documentation helps
<beneroth> guidelines are often: if you create the memory (pass in a pointer), its your responsibility (which does native automatically take care of, afaik?). and if you get the pointer from the library, then the library is responsible. often there are also library specific shutdown or free functions.
<beneroth> but it's not in any way ensured that a certain library behaves that way. documentation must be checked.
<Regenaxer> yes
<beneroth> the profiler tool "valgrind" can be used to find memory leaks
Hunar has quit [Quit: Client closed]
razzy has joined #picolisp
razzy has quit [Ping timeout: 260 seconds]
razzy has joined #picolisp
<razzy> Regenaxer: I see now, thank you. I "rediscovered" (call) in 60 functions from blog. so far i think (pipe) is not needed. I am also looking for option to send data from pil into stdin | fzf something like "(history) | (call fzf)" .
<Regenaxer> Yes, but the trick is indeed 'call' inside a 'pipe'
<Regenaxer> Because the output of call cannot be used
<Regenaxer> it prints to stdout
<Regenaxer> Thus a 'pipe' process is needed
<razzy> Regenaxer: ah, it prints into REPL, but i cannot work with it,... it seems
<Regenaxer> No, it does not print into the REPL
<Regenaxer> fzf prints the *result* (after Enter) to *its* stdout
<Regenaxer> (the user interaction goes to stderr as we saw at PilCon)
<Regenaxer> So the stdout of the called fzf needs to be connected to some channel in pil
<Regenaxer> This is what pipe does
<razzy> return from (call 'fzf) prints into screen but not REPL. yes?
<Regenaxer> it prints to stdout
<razzy> i think i understand
<Regenaxer> the stdout is by default connected to /dev/tty
<Regenaxer> which is the terminal, yes
<Regenaxer> The pil REPL always reads the current input channel (by default stdin) and print to the current output channel (by default stdout)
<razzy> thank you.
<Regenaxer> No problem :)
<razzy> any way to send data from pil into (call 'fzf) stdin ?
<razzy> i suspect (out) in play
<Regenaxer> Right, this is what (out 'lst ...) does
<Regenaxer> 'call' can only pass command line arguments
<Regenaxer> which may be named pipes (fifos) or files of course
<razzy> I do not know how to combine (out) for writing to stdin and (call)
<Regenaxer> (out 'lst
aw- has quit [Quit: Leaving.]
<razzy> and pipe
<Regenaxer> yes
<Regenaxer> 'pipe' has two forms
<razzy> i will look
<Regenaxer> (pipe (expression) ...)
<Regenaxer> this reads stdout of (expression) only
<Regenaxer> so cannot be used to send to stdin
<Regenaxer> (out '("program) ... sends to stdin of program
<razzy> yes
<razzy> I am looking at (doc 'pipe)
<Regenaxer> good
<Regenaxer> As I understood, you need (pipe (call "fzf" "--somearg" "--anotherarg") (read) or (line))
<Regenaxer> This might also work (pipe (out (list "fzf" "--somearg" "--anotherarg") (prinl "something)) (read) or (line))
<Regenaxer> :)
<razzy> Regenaxer: that solves use case we discussed
<razzy> at pilcon
<Regenaxer> ok, so I understood
<Regenaxer> But I think (pipe (out (list "fzf" will not work
<Regenaxer> because it redirects stdin of fzf
<Regenaxer> but stdin is needed for user input
<razzy> your second one might solve all my use cases
<Regenaxer> Then no user interaction?
<Regenaxer> typing keys to fzf
<razzy> One option would be write to file, than process with fzf.
<beneroth> that what pipe is for :)
<Regenaxer> T
<beneroth> or even (out 'lst ...)
<beneroth> (but then you get no response :D )
<razzy> I will try (pipe (out (call
<razzy> Thank you all, I will try in two hours time.
<Regenaxer> 👍
<beneroth> if you start a terminal/repl/shell within/from another, it's not part of the original one, but like a second layered on top of the existing.
<beneroth> once you leave the top one, the bottom one becomes active again
<beneroth> you cannot see that on the screen, as it looks like one, but it's multiple processes, the bottom ones halting when the top one start to interact with your terminal stdin/stdout
<razzy> bb
<razzy> bbl
<beneroth> maybe this helps.. if not, ignore it :D
<beneroth> bb
razzy has quit [Ping timeout: 260 seconds]
razzy has joined #picolisp
razzy has quit [Ping timeout: 245 seconds]
razzy has joined #picolisp
razzy has quit [Ping timeout: 260 seconds]
razzy has joined #picolisp
razzy has quit [Ping timeout: 245 seconds]
beneroth has quit [Quit: Leaving]
razzy has joined #picolisp
razzy has quit [Ping timeout: 265 seconds]
razzy has joined #picolisp
razzy has quit [Ping timeout: 252 seconds]
razzy has joined #picolisp
razzy has quit [Ping timeout: 260 seconds]
razzy has joined #picolisp
razzy has quit [Ping timeout: 265 seconds]
razzy has joined #picolisp
razzy has quit [Ping timeout: 252 seconds]
razzy has joined #picolisp