Recent posts

#11
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.
#12
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




#13
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.
#14
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


#15
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.
#16
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?
#17
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.
#18
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!
#19
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)
#20
newLISP in the real world / Re: Lint and/or code formattin...
Last post by dukester - February 15, 2024, 01:08:18 PM
Thx ...