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

Topics - IVShilov

#1
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?
#2
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?
#3
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.
#4
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 ]
#5
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?
#6
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?
#7
May be I don't understand recursive comparision doing by "=", but I see no logic in this:
newLISP v.10.7.1 32-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h
> (= '(true) '(true nil))
nil
> (= '(true nil) '(true))
true

And another case on numbers:
> (= '(1 0) '(1)) #-> true?
nil
>

Bug or feature?
#8
Trying to understand how dump work on variable which not set
newLISP v.10.7.1 32-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h
# (WindowsXP)
> (setq R '()) (time (push (dump x) R -1) 10 )(map unique (transpose R))
((5249584) (256) (5243024) (5243024) (5243024))


I get in such odd situation: RAM exhausted, error occurs, but no RAM was released and REPL still works.

See:
(setq R '()) (time (push (dump x) R -1) 100000000 ) (map unique (transpose R))
()

ERR: not enough memory in function dump
> (delete 'x) # more than minute for evaluation
true
> # still 2Gb RAM
> (reset)
> # no effect
> (symbols)

ERR: not enough memory in function symbols
> (dotree (s MAIN) (delete s true))

ERR: not enough memory
> (sys-info)

ERR: not enough memory
> (delete 'x) # try again

ERR: not enough memory
> (exit)

ERR: not enough memory

Nothing helps and I have to kill process.

Bug or a feature?

I mean is it points to some newlisp lack or I must be more careful with all memory-related functions?



UPD:

This crash test is reproductible:
> (setq R '()) (time (push (dump x) R -1) 100000000 ) (map unique (transpose R))
()

ERR: not enough memory in function dump
> (delete 'R) (reset)

 - memory released and came back to normal values,

but repeat
> (setq R '()) (time (push (dump x) R -1) 100000000 ) (map unique (transpose R))
lead to endless "ERR: not enough memory", 2Gb RAM and 50% CPU owned by newlisp.exe, and nothing helps except kill process.
#9
On python I work with ipython IDE and found it very useful.

Does it possible to have for newlisp have a table of pairs:

    - IN with input command,

    - OUT with saved corresponding output

for analyse it and get useful snippets written in past?



Input can be catched in reader-event, but I have no idea how to catch output - no output-event, no $last-output variable.
#10
newLISP newS / rotate bug on WIN7 x64
August 11, 2018, 10:52:07 AM
See this:
newLISP v.10.7.1 64-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h

> (rotate (sequence 0 24) -25 ) # BUG:
(0)
> (rotate (sequence 0 24) -24 ) # all OK:
(24 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23)
> (rotate (sequence 0 24) -26 ) # all OK again:
(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 0)
> (letn (x 25) (rotate (sequence 0 x) (- (inc x)) )) # again all OK, but must be BUG:
(26 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25)
> (rotate (sequence 0 4) -5 ) # BUG:
(0)
> (rotate (sequence 0 5) -6 ) # BUG:
(0)
>
#11
I spent 8 hours figuring out HOW it works in windows cmd.exe and found a paradox.

Two paradoxes.

Try this by yourself, all code in this post is copy and paste from cmd.exe window.



Starts CMD.EXE, and newlisp.exe without any init.lsp, and put him a valid cyrillic filepath as first parameter:


D:tmp>r:binnewlispnewlisp.exe -n "D:tmpЁ.doc"
newLISP v.10.7.1 64-bit on Windows IPv4/6 UTF-8 libffi, options: newlisp -h

> (last (main-args))
"D:\tmp\╨╕.doc"             # two symbols - not one, it's UNICODE
> (load {R:binnewlispmodulesiconv.lsp})
MAIN
> (file? (last (main-args)))  # may be it understands as valid path?
nil
> (Iconv:convert (last (main-args)) {UTF-8} {CP866}) # OK, de-UNICODE it
"D:\tmp\и.doc"
> # one symbol, but there must be "Ё"!

After hours of en- decoding between UTF-8, CP866 and CP1251 I have lucky shot in the dark and have paradox one: UTF8-path, decoded in CP866, must be decoded as CP1251 to CP866 again:

> (Iconv:convert (Iconv:convert (last (main-args)) {UTF-8} {CP866}) {CP1251} {CP866})
"D:\tmp\Ё.doc"
> #  no logic, but now we have a readable file path!
> (file? (Iconv:convert (Iconv:convert (last (main-args)) {UTF-8} {CP866}) {CP1251} {CP866}) ) # but what about this thinks newlisp itself?
nil

Newlisp think that there is no such file, but I think it is, I see "D:\tmp\Ё.doc".

Paradox two:

> (write-file {D:tmp1.txt} {1}) # OK, newlisp, does the file you create by yourself...
1
> (file? {D:tmp1.txt}) # ... would be a truly file?
true
> (write-file {D:tmpЁ.txt} {Ё}) # OK, now special case
1
> (file? {D:tmpЁ.txt})
true
> (file? {D:tmpЁ.doc})
nil
>


Ok, explorer.exe, what do you think about that?

Ё.doc:
[attachment=1]Ё.doc.jpg[/attachment]
Ё.txt
[attachment=2]Ё.txt.jpg[/attachment]

PPL, I think only some kind of Data Flow Diagram may clearly shows whats going under the hood of GUI and where the silent charset translations take place.
[attachment=0]DFD CMD-newlisp-OS.jpg[/attachment]
As I know, CMD.EXE works in CP866, FileSystem store file paths in CP1251, and newlisp.exe internally works in UTF-8. Let's discuss