Recent posts

#21
newLISP and the O.S. / Re: Windows clipboard
Last post by Yael - November 07, 2023, 02:12:09 AM
As an example, in a Windows *.bat file use this:

echo "%var%" | clip.exe
pasteclipboard.exe
yournewlispfile.exe

The file yournewlispfile.exe is your newlisp compiled file, which must include these commands:

(set 'option (exec "pasteclipboard.exe"))
(set 'myvar(parse (option 0)))

I know it is a dirty way of doing things, but honestly after struggling with dll's import I failed miserably.

#22
newLISP and the O.S. / Re: Windows clipboard
Last post by Yael - November 07, 2023, 02:01:55 AM
I am now attaching a zipped file with the pasteclipboard.exe here:
#23
newLISP in the real world / Does (reset) restores the top-...
Last post by IVShilov - November 07, 2023, 12:06:07 AM
Info from manual :

reset restores the top-level variable environment using the saved variable environments on the stack.

But I can't "restores the top-level variable environment using the saved variable environments on the stack" using it:

newLISP v.10.7.5 64-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h

> (crc32 (string (symbols)))
3617620833
> (prompt-event (fn () (string (args 0) ":" (crc32 (string (symbols))) " > ")))
$prompt-event
MAIN:1539437814 > (delete 'a)
true
MAIN:1539437814 > a
nil
MAIN:2595764761 > ## state change: 2595764761
MAIN:2595764761 > (ref "a" (map term (symbols)))
(49)
MAIN:2595764761 > ## sym a exists
MAIN:2595764761 > (delete 'a)
true
MAIN:1539437814 > ## we come back in 1539437814
MAIN:1539437814 > (ref "a" (map term (symbols)))
nil
MAIN:1539437814 > ## no sym a in MAIN
MAIN:1539437814 >

MAIN:1539437814 > a
nil
MAIN:2595764761 > ## sym a exist again but now we try to clean a context MAIN by reset
MAIN:2595764761 > ## newlisp manual: " reset restores the top-level variable environment using the saved variable environments on the stack. "
MAIN:2595764761 > (reset)
MAIN:2595764761 > (ref "a" (map term (symbols)))
(49)
MAIN:2595764761 > ## sym a exists
MAIN:2595764761 >

Bug or feature?
#24
newLISP and the O.S. / Re: Windows clipboard
Last post by cameyo - November 06, 2023, 01:12:31 PM
Thanks.
I can use the "clip" command, but where is "pasteclipboard.exe" ?
I have found: "powershell get-clipboard" to get text from clipboard.
#25
newLISP and the O.S. / Re: Windows clipboard
Last post by Yael - November 05, 2023, 02:41:18 AM
I use a call to pasteclipboard.exe to read from the clipboard. Here, an example:

(set 'option (exec "pasteclipboard.exe"))
(set 'optid (parse (option 0)))
(when (= (join optid) "0") (myfunction))
.
.
.

To put something on the clipboard I call clip.exe (all of this under Windows OS)
#26
newLISP in the real world / Re: Reading keyboard input
Last post by IVShilov - October 26, 2023, 10:56:31 AM
Another bug on this way: timer and read-key can't used together
(setq c nil interval 0,001)
(define (output)
    (if c
        (begin
          (print (char c))
          (setq c nil)
          ))
    (timer 'output interval)
    )
(output)
In console:
      > (setq c 100)
      100
      > d

      > (setq c (read-key))
      13
      0 > ## a context "0" ???

      0 > (context)
      MAIN
      >
#27
newLISP in the real world / Re: Reading keyboard input
Last post by IVShilov - October 26, 2023, 10:44:47 AM
AutoHotKey? Can't even imagine this.

Enchanced REPL is like a emacs/readline but for one string:
 - autocompletion by TAB:
     - functions using (filter lambda? (symbols)) 
     - args using (type) and function definitions
 - swapping two elements in line by C-t|C-M-t
 - highlight substrings using xterm esc-sequences and ConEmu's interface
and so on.
For example, look at ipython.
#28
newLISP in the real world / Re: Reading keyboard input
Last post by cameyo - October 26, 2023, 07:37:53 AM
Sorry, I can't help you.
But what do you mean by "enhanced REPL"?
I use Notepad++ connected to a REPL via Autohotkey script.
Far more powerful than only REPL.
Thanks.
#29
newLISP in the real world / Re: Reading keyboard input
Last post by IVShilov - October 26, 2023, 06:18:38 AM
Yes, everything is fine with blocking form of read-key: it catch F1, UTF8 two-byte codes, and even CTRL-C (!) returs code 3.

Problems in non-blocking reading:
1) F1 (code 0 59) because 0 is default result of (read-key true) means "no key pressed", and IMHO it must return nil;
2) UTF8 non-onebyte char - leads to infinite loop and crash.
This two problems block for me creating enhanced REPL.
PS Does someone knew how to catch win32 keyboard events  like key-press|key-release ?
I have weak skills in FFI

#30
newLISP in the real world / Re: Reading keyboard input
Last post by cameyo - October 26, 2023, 04:28:10 AM
This works for me:

(define (keys)
  (local (k)
    (while (!= (setq k (read-key)) 13)
      (setq s (string k))
      (println s))))

(keys)
;-> 1   ; Ctrl-A
;-> 111 ; O
;-> 79  ; o
;-> 0
;-> 59  ; F1
;-> 0
;-> 60  ; F2
;-> 224
;-> 81  ; PageUp
;-> 224
;-> 72  ; Up
;-> 224
;-> 77  ; Right
;-> 224
;-> 80  ; Down
;-> 224
;-> 75  ; Left