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

#1
newLISP and the O.S. / Re: Build newLISP for win10 64bit
December 16, 2023, 11:13:24 AM
Thank you!
#2
newLISP in the real world / Re: Reading keyboard input
November 18, 2023, 08:54:54 AM
Found solutions.

Quote1) 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.

Explanation of problem:
(import "msvcrt.dll" "_getch")
(import "msvcrt.dll" "_kbhit")
(exec "chcp 65001")
(setq n 0)
(while (< n 7)
    (if (= 1 (setq k (_kbhit) ))
(println (++ n) ":" k ":" (_getch) ":" (_kbhit))
(setq n 0)
)
    )
  )
1:1:13:0   <----------- ENTER, one catch, code 13, and kbhit returns 0
1:1:224:1  <----------- press UP: two codes: 224 and next 72
2:1:72:0
1:1:0:1    <----------- press F1: two codes: first 0, kbhit still returns 1
2:1:59:0   <-------------------------------- second: 59, after that kbhit returns 0
1:1:145:1  <----------- enter "ё": first code 209 was disappear, getch return second: 145
2:1:145:1  <----------- AND kbhit still returns 1:
3:1:145:1
4:1:145:1
5:1:145:1
6:1:145:1
7:1:145:1
1
> ё        <----------- and ё somehow printed by default newlisp REPL
Solutions is:
1) for catch F1-F12: import kbhit and check if key was pressed;
2) UTF8 in cmd.exe: DO NOT (exec "chcp 65001"), because it enable UTF8 input AND output.
It's hard to even imagine keyboard with button for every char in UTF8 set, so it will be quite enough to enable UTF8-output only:
(import "kernel32.dll" "SetConsoleOutputCP")
(import "kernel32.dll" "GetConsoleOutputCP")
> (SetConsoleOutputCP 866) (GetConsoleOutputCP) (char 937)
1
866
"╬й"          <----------- FAIL
> (SetConsoleOutputCP 65001) (GetConsoleOutputCP) (char 937)
1
65001
"Ω"           <----------- SUCCESS
> (import "kernel32.dll" "GetConsoleCP")
GetConsoleCP@CB3855F0
> (GetConsoleCP)
866           <----------- this is INPUT codepage
> (GetConsoleOutputCP)
65001         <----------- this is OUTPUT codepage
>
More info here
Complete solution is in use "Win32 Console API".
#3
newLISP and the O.S. / Re: Build newLISP for win10 64bit
November 12, 2023, 10:59:24 PM
Maybe in 2019 it was so simple,but in 2023 it is not :)
TDM have no ls, rm utilities, so I cannot do a "./configure" or "make clean".
MSYS have, but it not appropriate for building.

Can somebody explain step by step what I have to do to build newlisp from souce?

First: install TDM-GCC, ok, what next?
#4
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?
#5
newLISP in the real world / Re: Reading keyboard input
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
      >
#6
newLISP in the real world / Re: Reading keyboard input
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.
#7
newLISP in the real world / Re: Reading keyboard input
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

#8
Also, UTF8 letter crash newlisp capturing keypress in non-blocking mode :

(while (!= 3 (print (read-key true))) (print ":" (read-key true) "|"))
0:0|0:0| ...
after input "ё" newlisp stuck and cmd window close.
#9
newLISP in the real world / Reading keyboard input
October 22, 2023, 07:29:32 AM
Hi.
[windows 10, newLISP v.10.7.5 64-bit on Windows IPv4/6 UTF-8 libffi]

Found, that non-blocking mode (read-key true) cannot get F1-F12 keycodes because return 0 when nothing pressed, when, for example, F1 key is (0 59):
> (read-key) (read-key)
0
59
- first call returns 0, second call returns 59. 

Under the hood read-key use kbhit() and getch():

/* thanks to Peter van Eerten for contributing this function */
/* included non-blocking ability 10.7.3, LM */

CELL * p_readKey(CELL * params)
{

#if defined(WINDOWS) || defined(OS2)
if(!isNil(evaluateExpression(params)) )
{
if(kbhit())
return(stuffInteger(getch()));
else
[b][u]return(stuffInteger(0));[/u][/b]
}
else
return(stuffInteger(getch()));
#else
...
 /* not Windows or OS2 */
}

As I understand in this place
 return(stuffInteger(0));
(read-key true) returns 0 when nothing has pressed.
I think it must returns nil in this case .

The questions:
1) Is it right place to change behavior and nil is right solution?
2) How to do it right, which C-code must be there and how to rebuild sources?
#10
A solution found (sorry, attach a picture because of forum internal errors).
#11
Anything else we might add? / Need a peek for WINDOWS
September 13, 2021, 08:26:43 AM
Hello.

It was big PITA when I found that win-version of newlisp have no peek.

But I found a workaround (http://www.newlispfanclub.alh.net/forum/viewtopic.php?f=9&t=5139">http://www.newlispfanclub.alh.net/forum/viewtopic.php?f=9&t=5139) :
(define (peek-pipe fd)
  (letn (pos (seek fd)
    size (seek fd -1))
    (seek fd pos)
    size
    ))

May be it's better place for posting that.
#12
Hi.

I try to wrap (xml-type-tags) and (xml-parse) into one safe function without side effects.

So I have to pass params to it.

Problem with applying param to (xml-type-tags) in function:
(xml-type-tags nil nil nil nil)
(xml-parse {<br/>} 31)

returns ((br))

but
(apply xml-type-tags '(nil nil nil nil))
(xml-parse {<br/>} 31)

returns ((nil br ())) .

[ newLISP v.10.7.5 64-bit on Windows IPv4/6 UTF-8 libffi ]
#13
Hi all.

When wrapper sxml:parse called from external function, all symbols goes to context "sxml":
((define (sxml:parse xml-source d)
   (xml-type-tags nil nil nil nil)
   (xml-parse xml-source d)
   )
 {<br/>}
31
 )
returns ((br)) , but:
((define (some-function xml-source)
   (sxml:parse xml-source 31)
   )
 {<br/>}
 )
returns ((sxml:br))Bug?
#14
newLISP newS / Re: Stable Release newLISP v.10.7.5
November 11, 2020, 01:11:13 AM
Hi.

Bug found, process crashes by regex call:
r:binnewlisp>newlisp.exe -n                                              
newLISP v.10.7.5 64-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h
                                                                           
> (sys-info)                                                                
(428 576460752303423488 399 1 0 2048 0 6316 10705 1414)                    
> (regex {EdQ} {1} 0)                                                    
                                                                           
r:binnewlisp>                                                            
#15
newLISP and the O.S. / peek for WINDOWS
September 07, 2020, 10:05:35 AM
Hi there.

I found that it works like peek on WINDOWS:
(define (peek-pipe fd)
  (letn (pos (seek fd)
    size (seek fd -1))
    (seek fd pos)
    size
    ))

so now we can safely read a pipe from a subprocess without risk of blocking:
(define (read-pipe fd)
  (letn (buf "")
    (read fd buf (peek-pipe fd))
    buf
    ))


Can it be replacement for peek?

Any other comments?