Recent posts

#21
So, what can you actually DO with newLISP? / (send 'Hello 'to World)
Last post by pber - April 15, 2024, 07:13:47 AM
Many thanks, @itistoday, for you effort on newLISP.

I hope Lutz is in great form, today, just... elsewhere. I`m studing his codebase and I`m starting to feel a profound feeling of respect and regard for him and his code, which is great (IMHO).

I hope to publish something about my project (Ike) in order to find help from you Lisp coders.
I'm a f* C/C++ coder. I know lisp from decades (because I tried to use Xemacs/Emacs for at least 15 years), but I`m still not able to think, in Lisp.
I understand I think just in C, C++ or Smalltalk, but not in Lisp...
#22
Anything else we might add? / Re: v10.76 ffi interface does ...
Last post by sjain59 - March 13, 2024, 11:41:57 PM
I apoligize humbly. I have reproduced your result. I must have done something wrong to get the segfault. Many thanks.
#23
Anything else we might add? / Re: v10.76 ffi interface does ...
Last post by vashushpanov - March 13, 2024, 09:19:57 PM
(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "2,07"))

result 2,069999933242798
(with comma)

(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "2.07"))

result 2

(import "libc.so.6" "strtod" "double" "char*")
(println (strtod "2,07"))

result 2,07

(import "libc.so.6" "strtod" "double" "char*")
(println (strtod "2.07"))

result 2




#24
Anything else we might add? / Re: v10.76 ffi interface does ...
Last post by sjain59 - March 13, 2024, 08:11:45 AM
Try with value 2.07. It gives segmentation fault here. I was aware that 3.14 is reported as 3.14 (with some fractional error) but thought it fit only to report the segfault. Thanks. Kindly help.
#25
Anything else we might add? / Re: v10.76 ffi interface does ...
Last post by vashushpanov - March 12, 2024, 07:19:05 PM
(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "3.07"))
result = 3

With comma:
(import "libc.so.6" "strtof" "float" "char*")
(println (strtof "3,07"))
result = 3,069999933242798


#26
Anything else we might add? / v10.76 ffi interface does not ...
Last post by sjain59 - March 09, 2024, 10:33:24 PM
There is a library, called exodriver downloadable from 'labjack' which gives its library version (2.07) as a 32 bit float through it's function LJUSB_GetLibraryVersion().This I have verified by importing this function in another programming language.

But newLisp v10.76 returns a value 0 instead of 2.07 when the following expression is used:

(import "liblabjackusb.so" "LJUSB_GetLibraryVersion" "float") followed by (LJUSB_GetLibrarVersion) returns a value 0 instead of 2.07.

Perhaps that is because "float" is a cut down version of "double"?

I just checked that there is segmentation fault reading a flost from libc on linux 64 bit, as follows:

(import "libc.so.6" "strtof" "float" "char*")
(strtof "2.07")
yields segmentation fault.

I would appreciate if this issue is resolved.
#27
newLISP in the real world / Re: Lint and/or code formattin...
Last post by dukester - February 22, 2024, 07:41:57 AM
Yes! That works well now. Thank you. What was wrong with the code?
#28
newLISP in the real world / Re: Lint and/or code formattin...
Last post by vashushpanov - February 22, 2024, 01:19:40 AM
oh!

#!/usr/bin/env newlisp
;; indent-newlisp.lsp
;; Author: ssqq
;; http://www.newlisp.cn
;; usage:
;; ~> newlisp indent-newlisp.lsp your-script.lsp 4 > output.lsp

(define (indent-code input-file (indent 2))
    (local (v-level new-level file-txt file-lines indent-line indent-lines)
        (setq v-level 0)
        (setq file-text (read-file input-file))
        (setq file-lines (map trim (parse file-text "\n")))
        (dolist (v-line file-lines)
            (setq new-level (get-new-level v-line v-level))
            (if (starts-with v-line ")")
                (setq indent-line (get-indent-line new-level v-line indent))
                (setq indent-line (get-indent-line v-level v-line indent))
            )
            (push indent-line indent-lines -1)
            (setq v-level new-level)
        )
        (println (join indent-lines "\n"))
    )
)

(define (get-new-level v-line v-level)
    (local (close-amount open-amount freeze-line)
        (setq freeze-str (replace {".*?[^\\]"}   v-line "" 0))
        (setq freeze-str (replace {{.*?[^\\]}}   v-line "" 0))
        (setq freeze-str (replace {\[.*?[^\\]\]} v-line "" 0))
        (setq freeze-str (replace {(?:^|\s)(?:\;|\#).*?$} v-line "" 0))
        (find-all {\(} freeze-str)
        (setq open-amount $count)
        (setq v-level (+ open-amount v-level))
        (find-all {\)} freeze-str)
        (setq close-amount $count)
        (setq v-level (- v-level close-amount))
    )
)

(define (get-indent-line v-level v-line indent)
    (let (indent-space {})
        (setq indent-space (dup " " (mul v-level (int indent))))
        (append indent-space v-line)
    )
)

(setq input-file (main-args 2))
(setq indent (main-args 3))
(indent-code input-file indent)

(exit)

This code works.
#29
newLISP in the real world / Re: Lint and/or code formattin...
Last post by dukester - February 19, 2024, 06:32:20 AM
@vashushpanov Thank you for the script! 🙏

I just tried to run your script on a file that I wanted to clean up. Sadly there was zero output.
I'm running newLISP v.10.7.5 64-bit on Linux IPv4/6 UTF-8, so maybe the regex you use in the script need to be updated? I get no error messages - just zero output!
#30
newLISP in the real world / Re: Lint and/or code formattin...
Last post by vashushpanov - February 19, 2024, 01:25:19 AM
It is a long time ago I was get this script.


#!/usr/bin/env newlisp
;; indent-newlisp.lsp
;; Author: ssqq
;; http://www.newlisp.cn
;; usage:
;; ~> newlisp indent-newlisp.lsp your-script.lsp 4 > output.lsp

(define (indent-code input-file (indent 2))
    (local (v-level new-level file-txt file-lines indent-line indent-lines)
        (setq out-data "")
        (setq v-level 0)
        (setq file-text (read-file input-file))
        (setq file-lines (map trim (parse file-text "\n")))
        (dolist (v-line file-lines)
            (setq new-level (get-new-level v-line v-level))
            (if (starts-with v-line ")")
                (setq indent-line (get-indent-line new-level v-line indent))
                (setq indent-line (get-indent-line v-level v-line indent))
            )
            (push indent-line indent-lines -1)
            (setq v-level new-level)
        )
        (write-file input-file (join indent-lines "\n"))
    )
)

(define (get-new-level v-line v-level)
    (local (close-amount open-amount freeze-line)
        (setq freeze-str (replace {".*?[^\\]"}  v-line "" 0))
        (setq freeze-str (replace {{.*?[^\\]}}  v-line "" 0))
        (setq freeze-str (replace {\[.*?[^\\]\]} v-line "" 0))
        (setq freeze-str (replace {(?:^|\s)(?:\;|\#).*?$} v-line "" 0))
        (find-all {\(} freeze-str)
        (setq open-amount $count)
        (setq v-level (+ open-amount v-level))
        (find-all {\)} freeze-str)
        (setq close-amount $count)
        (setq v-level (- v-level close-amount))
    )
)
(define (get-indent-line v-level v-line indent)
    (let (indent-space {})
        (setq indent-space (dup " " (mul v-level (int indent))))
        (append indent-space v-line)
    )
)

(setq input-file (main-args 2))
(setq indent 2)
(indent-code input-file indent)

(exit)