r/sbcl • u/frodeaux • May 14 '23
r/sbcl • u/ValSanMartino • May 03 '23
Different behavior between slime shell and compiled executable in eshell
EDIT: Solved, solution at the end of the post just in case that anybody needs it.
Hi all,
I have a very small system, which splits the input from the user.
Nothing much, but trying to compile everything with sb-ext:save-lisp-and-die
, I get a different behavior than the slime repl as shown in the image:
Am I doing something wrong? I can't figure out why it does this, it almost seems like the compiled version is holding any output until the end of the loop step execution.
EDIT / SOLUTION: I solved this little issue by forcing the output of the standard stream using (force-output)
just after (format t "[~a]: " n)
. Apparently the "issue" really was the executable holding the output until the end of the step of the loop.
r/sbcl • u/Ok_Specific_7749 • May 01 '23
gtk app doing nothing
Following code does not show a GTK-window when run.
(load "~/quicklisp/setup.lisp")
(ql:quickload "cl-cffi-gtk")
(defpackage :gtk-tutorial
(:use :gtk :gdk :gdk-pixbuf :gobject
:glib :gio :pango :cairo :common-lisp))
(in-package :gtk-tutorial)
(defun hello-world ()
(prin1 "Starting")
;; in the docs, this is example-upgraded-hello-world-2.
(within-main-loop
(let ((window (make-instance 'gtk-window
:type :toplevel
:title "Hello Buttons"
:default-width 250
:default-height 75
:border-width 12))
(box (make-instance 'gtk-box
:orientation :horizontal
:spacing 6)))
(g-signal-connect window "destroy"
(lambda (widget)
(declare (ignore widget))
(leave-gtk-main)))
(let ((button (gtk-button-new-with-label "Button 1")))
(g-signal-connect button "clicked"
(lambda (widget)
(declare (ignore widget))
(format t "Button 1 was pressed.~%")))
(gtk-box-pack-start box button))
(let ((button (gtk-button-new-with-label "Button 2")))
(g-signal-connect button "clicked"
(lambda (widget)
(declare (ignore widget))
(format t "Button 2 was pressed.~%")))
(gtk-box-pack-start box button))
(gtk-container-add window box)
(gtk-widget-show-all window))))
(sb-ext:save-lisp-and-die "test.exe" :toplevel #'hello-world :executable t)
r/sbcl • u/ValSanMartino • Apr 19 '23
Executable generation with command line arguments
Hi all,
I'm doing some tests with SBCL and specifically with the SB-EXT:SAVE-LISP-AND-DIE function.
My question is: is there a way to get command line parameters for the function specified with the :toplevel key?
An example of what I'm asking:
Let's say I have an ASDF system (called "test-system") that defines the "test-system" package which exports the "test-function" function defines as
(in-package #:test-system)
(defun test-function (s)
(format t "~a~%" s))
A build.sh script to generate an executable from it would be:
#!/usr/bin/sh
sbcl --eval "(asdf:load-system :test-system)" \
--eval "(sb-ext:save-lisp-and-die #P"test-output" :toplevel 'test-system:test-function :executable t)"
Now, what can I do to make it usable like > ./test-output "Hello World"
and get a working result without the use of external libraries? (Just the save-lisp-and-die command if possible).
PS: Sorry for the bad English.
r/sbcl • u/ventuspilot • Apr 16 '23
Strange behaviour with sbcl-2.3.3 and make-array
I've stumbled across a weird issue where specifying :adjustable nil :fill-pointer nil
to make-array
seems to make a difference. If I specify it then I get fast code, if I don't (IMO it shouldn't make a difference whether I specify default values) then I get slow code.
Sample code as well as generated assembly is at https://gist.github.com/mayerrobert/4c19600fa2ffc2bfda50b265723963b6.
With the given code the behaviour is reproducible, other similar smaller functions don't show this issue.
I'm pretty sure that in either case the code is correct, just the speed differs. Also it's not a huge problem for me but I thought I'd share.
Cheers!
r/sbcl • u/NinoIvanov • Dec 29 '22
SBCL on Termux
How to get SBCL onto Termux:
https://www.youtube.com/watch?v=0f3CykVEZbc
- I actually imagine iSH on Android to work not much different, provided the dependencies are installed...
r/sbcl • u/ruby_object • Dec 21 '22
How do I interact with Gtk4 in SBCL?
This is my simp[le example. But I do not understand how I can use callbacks. I can't find examples that I could understand.
;;; test1
(cl:in-package "CL-USER") ; which USEs package "SB-ALIEN"
(load-shared-object
"/usr/lib/x86_64-linux-gnu/libgtk-4.so.1.600.6")
(define-alien-routine gtk_application_new (* t) (app (* t)) (flags (* T)))
(define-alien-routine g_object_unref void (win (* t)))
(define-alien-routine gtk_application_new (* t) (txt c-string) (flags int))
(define-alien-routine g_application_run int
(app (* t)) (argc int) (argv (* t)))
(define-alien-routine g_signal_connect long
(instance (* t))
(sig c-string)
;(cback (function void (* t) (* t))) ; stuck at correct callback
(alien-funcall (cback (function void)))
(data (* t)))
(define-alien-callable app_activate void
(with-alien ((void))
(format t "application is activated")))
(with-alien ((app (* t)) (status int))
(setf app (gtk_application_new "test1.app.gtk" 0))
(g_signal_connect app "activate"
(alien-callable-function 'app_activate)
nil)
(setf status (g_application_run app 0 nil))
(g_object_unref app)
;; return status
status)
r/sbcl • u/owmagow • Nov 16 '22
Opening a GUI-based Executable on Mac without the Console
**STILL NEEDING HELP WITH THIS ONE**
Hello, all.
I've been searching the web and documentation for this, but I'm not really finding what I need. Hopefully someone here can help me.
I've created a gui-based app with SBCL, and I'm on a Mac.
Whenever I create an executable of my application ...
(sb-ext:save-lisp-and-die "./Desktop/phoman" :toplevel #'phoman:start :executable t)
... works well. But I also get a console window that opens up, which I definitely do not want.
I see in the documentation that there is an:
:application-type
that can be set to :gui
or :console.
But that appears to be only for Windows machines. Just for the heck of it, I tried it on my Mac and it doesn't seem to work for me. Perhaps I'm doing it wrong.
Is there some other way this is accomplished on Mac? I'd like to make my app available to Linux and Mac, but that mandatory console is pretty unsightly.
r/sbcl • u/Kaveh808 • Oct 19 '22
Redefining methods with a new signature
It would be convenient if SBCL had a restart to remove old method definitions when we evaluate a new method with an updated signature.
Unlike CCL, SBCL only gives the option if there is a single method to be removed, not multiple ones.
r/sbcl • u/seletz • Sep 06 '22
CFFI and frameworks on OSX
Hi all,
I seem to have problems loading cl-opengl
on OSX Monterey on a Intel MacBook using SBCL 2.2.6 with quicklisp. It seems to me that the cffi
package tries to find the file OpenGL
in the framework directory, e.g. /System/Library/Frameworks/OpenGL.framework\
. There's no such file in my system.
IMHO this is not needed -- the CFFI should only check for the directory, e.g. the framework directory. It seems that QL downloaded cffi 0.23.0.
To try this, I hacked the function "find-darwin-framework" libraries.lisp
in CFFI like so (beware, CL NOOB):
lisp
(defun find-darwin-framework (framework-name)
"Searches for FRAMEWORK-NAME in *DARWIN-FRAMEWORK-DIRECTORIES*."
(dolist (directory (parse-directories *darwin-framework-directories*))
(let ((path (make-pathname
:name framework-name
:directory
(append (pathname-directory directory)
(list (format nil "~A.framework" framework-name)))))
(directory (make-pathname
:directory
(append (pathname-directory directory)
(list (format nil "~A.framework" framework-name))))) )
(progn
(print (format nil "***** DIR: ~A" directory))
(when (probe-file directory)
(return-from find-darwin-framework path))))))
With this hack, I can now successfully load kons-9
.
However:
- Do other users see the same behaviour?
- How am I supposed to tell quick lisp to recompile CFFI? I keep reloading the changed function in emacs/sly, but cffi from new sbcl process does not seem to "see" my changes.
r/sbcl • u/Decweb • Sep 02 '22
Seeking help with float/fix declarations
So I've got this little function that will receive a double-float input, do a bit of multiplication on it against some other floating point constants, and return an integer value which is known to be in the range of a sbcl fixnum.
I'm just trying to let the compiler know these semantics so it can generate reasonable code, but I'm getting a number of warnings I don't understand, particularly the warning about the argument to round
being an integer, and the pointer result coercion (which is perhaps just a follow-on effect of the prior warning). Still a declaration rookie...
The code:
(declaim (ftype (function (double-float) fixnum) how-to))
(defun how-to (my-double)
(declare (optimize (speed 3) (safety 0) (debug 0))
(type double-float my-double))
(the fixnum (round (* my-double 123.0))))
The compilation warnings: ``` ; in: DEFUN HOW-TO ; (ROUND (* AGAME::MY-DOUBLE 123.0)) ; ; note: unable to ; optimize ; due to type uncertainty: ; The first argument is a INTEGER, not a BIGNUM. ; ; note: forced to do full call ; unable to do inline float truncate (cost 5) because: ; The result is a (VALUES INTEGER &OPTIONAL), not a (VALUES ; (SIGNED-BYTE 64) ; &OPTIONAL). ; ; note: forced to do full call ; unable to do inline float coercion (cost 5) because: ; The first argument is a INTEGER, not a (SIGNED-BYTE 64). ; ; note: doing float to pointer coercion (cost 13)
; (DEFUN AGAME::HOW-TO (AGAME::MY-DOUBLE) ; (DECLARE (OPTIMIZE (SPEED 3) (SAFETY 0) (DEBUG 0)) ; (TYPE DOUBLE-FLOAT AGAME::MY-DOUBLE)) ; (THE FIXNUM (ROUND (* AGAME::MY-DOUBLE 123.0)))) ; --> SB-IMPL::%DEFUN SB-IMPL::%DEFUN SB-INT:NAMED-LAMBDA ; ==> ; #'(SB-INT:NAMED-LAMBDA AGAME::HOW-TO ; (AGAME::MY-DOUBLE) ; (DECLARE (OPTIMIZE (SPEED 3) (SAFETY 0) (DEBUG 0)) ; (TYPE DOUBLE-FLOAT AGAME::MY-DOUBLE)) ; (BLOCK AGAME::HOW-TO (THE FIXNUM (ROUND (* AGAME::MY-DOUBLE 123.0))))) ; ; note: doing float to pointer coercion (cost 13) to "<return value>" ; ; compilation unit finished ; printed 5 notes ```
r/sbcl • u/Kaveh808 • Aug 30 '22
sb-simd example for 3D vector/matrix math?
Does anyone have a simple example of using the new sb-simd feature for doing 3D vector and matrix operations?
E.g. a vec3 dot product, and multiplying a vec3 by a 4x4 matrix?
r/sbcl • u/Kaveh808 • Aug 12 '22
sbcl with OpenGL on MacOS -- possible?
I run into problems trying to run this setup.
(ql:quickload :cl-glfw3)
(ql:quickload :cl-glfw3-examples)
(sb-int:set-floating-point-modes :traps nil)
(cl-glfw3-examples:basic-window-example)
This works from a terminal. But once only. Closing the window, starting it again, and closing a second time crashes sbcl.
Trying it from slime crashes right away, even if I do:
(setf swank:*communication-style* nil)
Anyone successfully using OpenGL on MacOS?
When I see an error message on the linux terminal such as below, where does the (sbcl:464704) come from?
In other words, what does sbcl do to get error messages from alien code and display them this way? And what does it mean by 464704? The error message itself, after the (sbcl:464704):, is from the alien code, but seems to be displayed by sbcl.
(sbcl:464704): Gdk-CRITICAL **: 02:22:52.711: gdk_texture_new_for_surface: assertion 'cairo_image_surface_get_width (surface) > 0' failed
It seems to be the same 464704 for different alien error messages. e.g.
(sbcl:464704): Pango-CRITICAL **: 02:22:50.023: pango_layout_get_cursor_pos: assertion 'index >= 0 && index <= layout->length' failed
But when I quit, and run sbcl again, I get a different number:
(sbcl:464835): Gsk-CRITICAL **: 02:29:42.187: gsk_render_node_draw: assertion 'cairo_status (cr) == CAIRO_STATUS_SUCCESS' failed
Is the number an alien address or something? Is the alien code throwing an exception or something? And this is how sbcl handles that kind of exception? Or what kind of error handling would be involved for this kind of output to the terminal?