Ok_Specific_7749

joined 1 year ago
[–] Ok_Specific_7749@alien.top 1 points 1 year ago

Program :


(module-name MyTest)
(module-compile-options main: #t)

(define (main)
    (define ar ::java.util.ArrayList[symbol] (java.util.ArrayList))
    (ar:add 'a)
    (ar:size)
    (ar:add 1))
(main)

Error:


(compiling ./MyTest.scm to MyTest)
./MyTest.scm:9:13: warning - type integer is incompatible with required type symbol
./MyTest.scm:9:5: warning - cannot convert literal (of type gnu.math.IntNum) to ClassType gnu.mapping.Symbol
        0,32 real         0,53 user         0,07 sys
java.lang.ClassCastException: class gnu.math.IntNum cannot be cast to class gnu.mapping.Symbol (gnu.math.IntNum and gnu.mapping.Symbol are in unnamed module of loader 'app')
	at MyTest.main(MyTest.scm:9)
	at MyTest.run(MyTest.scm:5)

µ

[–] Ok_Specific_7749@alien.top 1 points 1 year ago

Indeed using compile the time reduced to 6s.
So one has to be careful before drawing conclusions.

[–] Ok_Specific_7749@alien.top 1 points 1 year ago

For me the availability of libraries is more important.
Even the size of the executable is not important.

 

sbcl-lisp : 0.7s

racket-scheme : 0.7s

ccl-lisp : 6s

kawa-scheme : 14s

abcl-lisp : 45s

[–] Ok_Specific_7749@alien.top 1 points 1 year ago

Thanks for answering/solving this problem. It was not obvious for me.
Now i have another question would it be possible to do something similar using sbcl or ccl. I.e. creating a compiled library and calling it from a main.lisp file.

 

The lisp program to compile :

library.lisp

(load "~/quicklisp/setup.lisp")
(declaim (optimize (speed 3) (safety 3) (space 0) (debug 3)))
(ql:quickload "defstar")

(defpackage package-library
    (:use #:cl #:defstar)
    (:export printstring))

(in-package :package-library)
(defun* (printstring -> boolean) ((s string))
    (princ s) t)

The lisp program performing the compilation :

compîle.lisp

(declaim (optimize (speed 3) (safety 3) (space 0) (debug 3)))
(load "~/quicklisp/setup.lisp")

(format t "~a~%" "COMPILING library.lisp")
(CL:COMPILE-FILE "library.lisp")

(format t "~a~%" "Done compiling")
(quit)

The script to perform the compilation :

rm *.abcl
echo "COMPILING"
time abcl --noinform --noinit --nosystem --load compile.lisp

The error/bug :


COMPILING library.lisp
; Compiling /mnt/xxx_data/Languages_ok/lisp/abcl/module/library.lisp ...
; (LOAD "~/quicklisp/setup.lisp")
; (DECLAIM (OPTIMIZE # ...))
; (QUICKLISP-CLIENT:QUICKLOAD "defstar")
; (DEFPACKAGE PACKAGE-LIBRARY ...)
Error loading /mnt/xxx_data/Languages_ok/lisp/abcl/module/compile.lisp at line 6 (offset 171)
#: Debugger invoked on condition of type ERROR
  DEFSTAR is not the name of a package.

[–] Ok_Specific_7749@alien.top 1 points 1 year ago

I found an interesting abcl function:

(add-to-classpath "some.jar")   

[–] Ok_Specific_7749@alien.top 1 points 1 year ago

Correction. Program works correctly with sbcl & abcl & ccl.
I just needed to put a softlink to whish executable (tk)

[–] Ok_Specific_7749@alien.top 1 points 1 year ago

No it works with kawa scheme like i specified.

[–] Ok_Specific_7749@alien.top 1 points 1 year ago

Program below does not work with ccl.


load "~/quicklisp/setup.lisp")
(ql:quickload "ltk")
(in-package :ltk-user)
(declaim (optimize (speed 3) (safety 3)))
(defun main()
  (with-ltk ()
   (let ((b (make-instance 'button
                           :master nil
                           :text "Press Me"
                           :command (lambda ()
                                      (format t "Hello World!~&")))))
     (pack b))))
(main)



 

How to write a "hello world" ltk application using ccl lisp ?

 

The following is a kawa scheme program consisting of 3 files

Mytest.scm


(module-name MyTest)
(module-compile-options main: #t)
(define (printc)
    (display "c"))
(require 'srfi-1) ;;  List Library
(define (main)
    (import MyTestA)
    (printa)
    (MyTestB:printb)
    (printc))
(main)

MyTestA.scm


(module-name MyTestA)
(module-export printa)
(define (printa)
    (display "A"))

MyTestB.scm


(module-name MyTestB)
(module-export printb)
(define (printb)
    (display "B"))

To compile & run,

rm -vf ./*.class
kawa -Dkawa.import.path="." -C ./MyTestA.scm
kawa -Dkawa.import.path="." -C ./MyTestB.scm
kawa -Dkawa.import.path="." --main -C ./MyTest.scm
kawa MyTest

How do i do the same thing in abcl lisp ?

[–] Ok_Specific_7749@alien.top 1 points 1 year ago

I use also kawa (a scheme). It has better documentation. https://www.gnu.org/software/kawa/pt01.html

[–] Ok_Specific_7749@alien.top 1 points 1 year ago

Program below works fine with sbcl & ccl.
For abcl i get alot of warnings, not errors,


(load "~/quicklisp/setup.lisp")
(declaim (optimize (speed 3) (safety 3)))

(ql:quickload "serapeum")

(defpackage alain
  (:use :cl :serapeum)
  (:export main));defpackage

(in-package :alain)

(declaim (type (integer) *anint*))
(defparameter *anint* 2)

(-> addtwo ( integer ) integer )
(defun addtwo (x)
  ( + *anint* x ))

(defun main ()
	(print (addtwo 3)));main

(in-package :cl)
(defun main ()
  (alain::main))
(main)

; Compilation unit finished ; Caught 22 WARNING conditions ; Caught 10 STYLE-WARNING conditions

[–] Ok_Specific_7749@alien.top 1 points 1 year ago

I just tried ccl on freebsd. I had only to download two files an executable fx86cl64 and an fx86cl64.image. It works nice.

I tried hy-lisp. The idea is good but it lacks features.

[–] Ok_Specific_7749@alien.top 1 points 1 year ago (5 children)

The first library i tried was serapeum.
https://github.com/ruricolist/serapeum
But abcl was spitting out alot of errors.

 

Personaly i found abcl a bad experience.
Thoughts on ecl & clisp ?

sbcl works nice & fine. But i't's the only lisp implementation i know.
There are good books on racket-scheme & chez-cheme.
The only book i know for lisp is, "Common lisp , a gentle introduction to symbolic computing".

 

I want to call the square root of 9 from Math:

I tried the following, but it does not work:


(defun main
    (format t "~a~%"
        (JAVA:JCALL (JAVA:JMETHOD "java.lang.Math" "sqrt" 9.0))))
(main)


Can someone provide a working ".lisp" file which calls the java sqrt function from 9 and prints the result 3 for the abcl implementation ?

 

A counter in racket-scheme:

#lang typed/racket

(define my-counter!
    (let ([t 0])
        (lambda ()
	        (set! t (+ 1 t))
	    t);lambda
	);let
);define 
(print (my-counter!))
(print (my-counter!))

A counter in sbcl-lisp:

load "~/quicklisp/setup.lisp")

(declaim (optimize (speed 3) (safety 3)))

(let ((c 0))
    (defun my-counter! ()
        (lambda ()
            (setf c (+ 1 c))
	    c); lambda
	 ) ;defun
) ;let

(defun main ()
(print (funcall (my-counter!)))
(print (funcall (my-counter!)))
)

(sb-ext:save-lisp-and-die "test.exe" :toplevel #'main :executable t)

Could someone elaborate why i need "funcall" in lisp and not in scheme ? And why the different placing of let ?

 

What are the strengths , weaknesses.
How to compare sbcl with clojure

view more: next ›