clisp always seems to segfault when trying to do graphics.

Discussion of Common Lisp
Post Reply
punchcard
Posts: 16
Joined: Fri Sep 26, 2014 5:50 pm

clisp always seems to segfault when trying to do graphics.

Post by punchcard » Wed Oct 15, 2014 11:30 pm

Know that clisp don't have a lot of support for gui stuff. But does anyone have some example code that works? I have looked through the library sites and even when using quicklisp in 90% of cases clisp just errors or segfaults when trying to do anything gui related. My system is debian and I don't have any issues with other librarys. got cffi installed. clisp is version 2.49.

The major annoying thing is for some reasion clisp does not understand when a librarys function is loaded. It always seems to insist on having the library explicitly declared in the source.

So even after I have loaded the library into clisp i still have to do library:function instead of just function.

That appears to be not what the creators of the few-and-far between examples or tutorials have written. I am guessing that the seg-fault is because of a lack of error handling when a forign function gets called in clisp that it cant find a binding for? or that somthing didn't get initalized?

hmmm....

Shame because lisbuilder seems to be the exception - the person who wrote that library wrote some great documentation. I just can't use it because of the constant seg-faults and as I said the issue with clisp not being able to load the basic examples without me having to go in and try and figure out what functions the example is using from the core libaries or if its from its own library set.

What I am looking for is a well documented or at least series of examples that I can use to make a gui or at a push a curses style terminal screen that will work with clisp. CFFI seems to load without issue, same with opengl, vecto works like a charm. I wish there was a way to make guis with vecto. Again a libary with a lot of love for the docs and examples there.

I have been trying to document the features of charms but like lisbuilder when I make a mistake or call a function without first figuring out the init settings it segfaults clisp. The wierdest thing is somtimes you evaluate a function in the libarary and all you get is a memory refrence spat back at you... Whats all that about? Is that a pointer to the binding? Thats one mini-project I have had on the side for a while now that I want to get finished is get the charms documentation into a state where a beginner could use it to do somthing usefull. Any help would be great on this. If you have any examples that you got to work in clisp with charms that would be fantastic.

Code: Select all

GNU CLISP 2.49 (2010-07-07) (built on Kashyyyk.rennes.ariadnext.com [127.0.1.1])
Software: GNU C 4.6.2 
gcc -falign-functions=4 -W -Wswitch -Wcomment -Wpointer-arith -Wimplicit -Wreturn-type -Wmissing-declarations -Wno-sign-compare -Wno-format-nonliteral -O -falign-functions=4 -DENABLE_UNICODE -DDYNAMIC_FFI -DDYNAMIC_MODULES -I.  -lreadline -lncurses -ldl /usr/lib/libavcall.so /usr/lib/libcallback.so  -L/usr/lib -lsigsegv libgnu_cl.a 
SAFETY=0 TYPECODES WIDE_HARD GENERATIONAL_GC SPVW_BLOCKS SPVW_MIXED TRIVIALMAP_MEMORY
libsigsegv 2.9
libreadline 5.2
libffcall 1.11
Features: 
(READLINE REGEXP SYSCALLS I18N LOOP COMPILER CLOS MOP CLISP ANSI-CL
 COMMON-LISP LISP=CL INTERPRETER SOCKETS GENERIC-STREAMS LOGICAL-PATHNAMES
 SCREEN FFI GETTEXT UNICODE BASE-CHAR=CHARACTER WORD-SIZE=64 PC386 UNIX)
C Modules: (clisp i18n syscalls regexp readline)
Installation directory: /usr/lib/clisp-2.49/
User language: ENGLISH
Machine: X86_64 (X86_64)
Is there anything wrong with how its setup? I know I must be doing somthing dumb.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: clisp always seems to segfault when trying to do graphic

Post by Goheeca » Thu Oct 16, 2014 2:27 am

The library:function means that the function is in the package library and you don't use-package that. To get a little insight into this look here.
For GUI I'd recommend the CommonQt binding for Qt. But feel free to look at my toy fusion of Cairo & SDL.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: clisp always seems to segfault when trying to do graphic

Post by Goheeca » Thu Oct 16, 2014 2:30 am

And perhaps try the SBCL implementation of CL, resp. there are many of them hence I recommend to explore them.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

punchcard
Posts: 16
Joined: Fri Sep 26, 2014 5:50 pm

Re: clisp always seems to segfault when trying to do graphic

Post by punchcard » Thu Oct 16, 2014 4:27 am

I am re-installing sbcl I couldn't get quicklisp to load any packages always got bizare errors.

Code: Select all

debugger invoked on a SB-INT:SIMPLE-READER-PACKAGE-ERROR in thread
#<THREAD "main thread" RUNNING {1002978E23}>:
  Package QL does not exist.

    Stream: #<SYNONYM-STREAM :SYMBOL *TERMINAL-IO* {10001DC673}>

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

(SB-IMPL::READ-TOKEN #<SYNONYM-STREAM :SYMBOL *TERMINAL-IO* {10001DC673}> #\q)
0[2] (load "~/quicklisp/setup.lisp")

T
0[2] (ql:quickload "qt")
To load "qt":
  Load 1 ASDF system:
    qt
; Loading "qt"
[package iterate].................................
[package closer-mop]..............................
[package closer-common-lisp]......................
[package closer-common-lisp-user].................
[package cl-ppcre]................................
..................................................
[package editor-hints.named-readtables]...........
[package babel-encodings].........................
[package babel]...................................
..................................................
[package cffi-sys]................................
[package cffi]....................................
..................................................
[package cffi-features]...

debugger invoked on a ASDF:OPERATION-ERROR in thread
#<THREAD "main thread" RUNNING {1002978E23}>:
  Error while invoking #<COMPILE-OP (:VERBOSE NIL) {1003CE8D03}> on
  #<MAKEFILE "qt" "so" "commonqt.pro">

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [RETRY ] Retry compiling #<MAKEFILE "qt" "so" "commonqt.pro">.
  1: [ACCEPT] Continue, treating compiling #<MAKEFILE "qt" "so" "commonqt.pro">
              as having been successful.
  2: [ABORT ] Give up on "qt"
  3:          Reduce debugger level (to debug level 2).
  4:          Exit debugger, returning to top level.

((SB-PCL::FAST-METHOD ASDF:PERFORM (ASDF:COMPILE-OP #:MAKEFILE))
 #<unavailable argument>
 #<unavailable argument>
 #<ASDF:COMPILE-OP (:VERBOSE NIL) {1003CE8D03}>
 #<#:MAKEFILE "qt" "so" "commonqt.pro">)
Hopefully this will fix it otherwise not sure how to proceed. Do you think its somthing to do with my system? Just seems weird - I must be doing somthing wrong. The programs cant possibly be this difficult to use or broken normally.

Cheers for the help you guys have been great.

P.S I find sbcl very hard to use compaired to clisp.

Update... just added rlwrap. Ah now its much easyer to use. Exelent.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: clisp always seems to segfault when trying to do graphic

Post by Goheeca » Thu Oct 16, 2014 6:15 am

Yeah, I'm using rlwrap too. ;)
Try troubleshoot it by manual compiling of the wrapper library. For me it's always worked after installation of required libraries.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

punchcard
Posts: 16
Joined: Fri Sep 26, 2014 5:50 pm

Re: clisp always seems to segfault when trying to do graphic

Post by punchcard » Thu Oct 16, 2014 8:45 am

Was sat there thinking over what you had said... Then it hit me - did I actually have the C libraries the wrapper was suposed to be binding to in the first place? :roll:

Well you can imagine my homer simpson like DOH. haha I downloaded about 100megs worth of C/C++ libariries and it installed fine (suprise suprise)

egg on my face. :lol:

Thought I was going crazy there for a while.

ahhh this works... Thank the McCarthy.

Code: Select all

#!/usr/bin/sbcl --script
 
; Also see http://pleasegodno.wordpress.com/common-lisp-tutorials/common-lisp-gui-programming-with-commonqt/introduction-to-commonqt/
; or see http://kvardek-du.kerno.org/2011/12/setting-up-commonqt-on-osx.html if you're still using Mac OS
 
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
(user-homedir-pathname))))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
 
(ql:quickload 'qt)
 
(defpackage :hello-qt
(:use :cl :qt)
(:export #:main))
 
(in-package :hello-qt)
(named-readtables:in-readtable :qt)
 
;;;;Hello Qt
 
(defun hello-qt()
(let* ((app (make-qapplication))
(label (#_new QLabel "<strong>Hello Qt!</strong>")))
(#_setWindowTitle label "Hello, Qt!")
(#_resize label 100 100)
(#_show label)
(unwind-protect
(#_exec app)
(#_hide label))))
(hello-qt)
Shame that the wordpress blog they refer to is now deleted...

That was the only example that worked that I could find on the net.

Other than that you have this..

http://cheryllium.wordpress.com/2014/02 ... utorial-1/

But I cannot get that to run. no completeled source to check either its all broken up all over the place. I am not sure if i typed it in wrong or if they are missing somthing important that the author just assumed that a beginer to that pacakage would know about programming qt already :roll: ....

My first thought is perhaps its looking for the qt stuff in the wrong place when it makes function calls... but thats just a guess.

But I think - never mind perhaps the main project webpage would have a rational example set to look at the learn from...

the first example... that also does not work.

Code: Select all

;;; -*- show-trailing-whitespace: t; indent-tabs-mode: nil -*-

;;; http://doc.trolltech.com/4.3/tutorial-t14.html

(defpackage :qt-tutorial-14
  (:use :cl :qt)
  (:export #:main))

(in-package :qt-tutorial-14)
(named-readtables:in-readtable :qt)

(defclass cannon-field ()
    ((current-angle :initform 45
                    :accessor current-angle)
     (current-force :initform 0
                    :accessor current-force)
     (timer-count :initform 0
                  :accessor timer-count)
     (auto-shoot-timer :accessor auto-shoot-timer)
     (shoot-angle :initform 0
                  :accessor shoot-angle)
     (shoot-force :initform 0
                  :accessor shoot-force)
     (target :initform nil
             :accessor target)
     (game-ended-p :initform nil
                   :accessor game-ended-p)
     (barrel-pressed-p :initform nil
                       :accessor barrel-pressed-p))
  (:metaclass qt-class)
  (:qt-superclass "QWidget")
  (:slots ("setAngle(int)" (lambda (this newval)
                             (setf (current-angle this)
                                   (min (max 5 newval) 70))))
          ("setForce(int)" (lambda (this newval)
                             (setf (current-force this)
                                   (max 0 newval))))
          ("void moveShot()" move-shot)
          ("void shoot()" shoot)
          ("void setGameOver()" set-game-over)
          ("void restartGame()" restart-game))
  (:signals ("angleChanged(int)")
            ("forceChanged(int)")
            ("void hit()")
            ("void missed()")
            ("void canShoot(bool)"))
  (:override ("paintEvent" paint-event)
             ("mousePressEvent" mouse-press-event)
             ("mouseMoveEvent" mouse-move-event)
             ("mouseReleaseEvent" mouse-release-event)))

(defmethod (setf current-angle) :around (newval (instance cannon-field))
  (let ((oldval (current-angle instance)))
    (prog1
        (call-next-method)
      (unless (eql oldval newval)
        (with-objects ((rect (cannon-rect instance)))
          (#_update instance rect))
        (emit-signal instance "angleChanged(int)" newval)))))

(defmethod (setf current-force) :around (newval (instance cannon-field))
  (let ((oldval (current-force instance)))
    (prog1
        (call-next-method)
      (unless (eql oldval newval)
        (with-objects ((rect (cannon-rect instance)))
          (#_update instance rect))
        (emit-signal instance "forceChanged(int)" newval)))))

(defun cannon-rect (instance)
  (let ((result (#_new QRect 0 0 50 50)))
    (#_moveBottomLeft result (#_bottomLeft (#_rect instance)))
    result))

(defun barrier-rect (instance)
  (#_new QRect 145 (- (#_height instance) 100) 15 99))

(defun barrel-hit-p (instance pos)
  (with-objects ((matrix (#_new QMatrix)))
    (#_translate matrix 0 (#_height instance))
    (#_rotate matrix (- (current-angle instance)))
    (with-objects ((br (barrel-rect))
                   (mapped-pos (#_map (#_inverted matrix) pos)))
      (#_contains br mapped-pos))))

(defun target-rect (instance)
  (let ((result (#_new QRect 0 0 20 10)))
    (with-objects ((to (#_new QPoint
                              (#_x (target instance))
                              (- (#_height instance)
                                 1
                                 (#_y (target instance))))))
      (#_moveCenter result to))
    result))

(defun barrel-rect ()
  (#_new QRect 30 -5 20 10))

(defun shot-rect (instance)
  (with-objects ((barrel-rect (barrel-rect)))
    (let* ((gravity 4.0d0)
           (time (/ (timer-count instance) 20.0d0))
           (velocity (shoot-force instance))
           (radians (* (shoot-angle instance) (/ pi 180.0d0)))
           (velx (* velocity (cos radians)))
           (vely (* velocity (sin radians)))
           (x0 (* (+ (#_right barrel-rect) 5.0d0) (cos radians)))
           (y0 (* (+ (#_right barrel-rect) 5.0d0) (sin radians)))
           (x (+ x0 (* velx time)))
           (y (+ y0 (* vely time) (- (* 0.5d0 gravity time time))))
           (result (#_new QRect 0 0 6 6)))
      (with-objects ((to (#_new QPoint
                                (round x)
                                (- (#_height instance) 1 (round y)))))
        (#_moveCenter result to))
      result)))

(defun is-shooting-p (instance)
  (#_isActive (auto-shoot-timer instance)))

(defun shoot (instance)
  (unless (is-shooting-p instance)
    (setf (timer-count instance) 0)
    (setf (shoot-angle instance) (current-angle instance))
    (setf (shoot-force instance) (current-force instance))
    (#_start (auto-shoot-timer instance) 5)
    (emit-signal instance "canShoot(bool)" nil)))

(defun set-game-over (instance)
  (unless (game-ended-p instance)
    (when (is-shooting-p instance)
      (#_stop (auto-shoot-timer instance)))
    (setf (game-ended-p instance) t)
    (#_update instance)))

(defun restart-game (instance)
  (when (is-shooting-p instance)
    (#_stop (auto-shoot-timer instance)))
  (setf (game-ended-p instance) nil)
  (#_update instance)
  (emit-signal instance "canShoot(bool)" t))

(defun move-shot (instance)
  (with-objects ((old (shot-rect instance)))
    (incf (timer-count instance))
    (with-objects ((new (shot-rect instance))
                   (tr (target-rect instance)))
      (cond
        ((#_intersects new tr)
         (#_stop (auto-shoot-timer instance))
         (emit-signal instance "hit()")
         (emit-signal instance "canShoot(bool)" t))
        ((or (> (#_x new) (#_width instance))
             (> (#_y new) (#_height instance))
             (with-objects ((br (barrier-rect instance)))
               (#_intersects new br)))
         (#_stop (auto-shoot-timer instance))
         (emit-signal instance "missed()")
         (emit-signal instance "canShoot(bool)" t))
        (t
         (let ((new (#_unite old new)))
           (#_delete old)
           (setf old new)))))
    (#_update instance old)))

(defmethod initialize-instance :after ((instance cannon-field) &key parent)
  (if parent
      (new instance parent)
      (new instance))
  (setf (auto-shoot-timer instance) (#_new QTimer instance))
  (connect (auto-shoot-timer instance) "timeout()" instance "moveShot()")
  (with-objects ((col (#_new QColor 250 250 200))
                 (pal (#_new QPalette col)))
    (#_setPalette instance pal))
  (#_setAutoFillBackground instance t)
  (new-target instance))

(defun new-target (instance)
  (when (target instance)
    (#_delete (target instance)))
  (setf (target instance)
        (#_new QPoint
               (+ 200 (random 190))
               (+ 10 (random 255))))
  (#_update instance))

(defun paint-shot (instance painter)
  (#_setPen painter (#_NoPen "Qt"))
  (with-objects ((brush (#_new QBrush (#_black "Qt") (#_SolidPattern "Qt"))))
    (#_setBrush painter brush))
  (with-objects ((rect (shot-rect instance)))
    (#_drawRect painter rect)))

(defun paint-cannon (instance painter)
  (#_setPen painter (#_NoPen "Qt"))
  (with-objects ((brush (#_new QBrush (#_blue "Qt") (#_SolidPattern "Qt"))))
    (#_setBrush painter brush))

  (#_save painter)
  (#_translate painter 0 (#_height (#_rect instance)))
  (with-objects ((rect (#_new QRect -35 -35 70 70)))
    (#_drawPie painter rect 0 (* 90 16)))
  (#_rotate painter (- (current-angle instance)))
  (with-objects ((rect (#_new QRect 30 -5 20 10)))
    (#_drawRect painter rect))
  (#_restore painter))

(defun paint-target (instance painter)
  (#_setPen painter (#_NoPen "Qt"))
  (with-objects ((brush (#_new QBrush (#_red "Qt") (#_SolidPattern "Qt"))))
    (#_setBrush painter brush))
  (with-objects ((rect (target-rect instance)))
    (#_drawRect painter rect)))

(defun paint-barrier (instance painter)
  (with-objects ((pen (#_new QPen (#_black "Qt"))))
    (#_setPen painter pen))
  (with-objects ((brush (#_new QBrush (#_blue "Qt") (#_SolidPattern "Qt"))))
    (#_setBrush painter brush))
  (with-objects ((rect (barrier-rect instance)))
    (#_drawRect painter rect)))

(defmethod paint-event ((instance cannon-field) paint-event)
  (with-objects ((painter (#_new QPainter instance)))
    (when (game-ended-p instance)
      (#_setPen painter (#_black "Qt"))
      (with-objects ((font (#_new QFont "Courier" 48 (#_Bold "QFont"))))
        (#_setFont painter font))
      (#_drawText painter (#_rect instance) (#_AlignCenter "Qt") "Game Over"))
    (paint-cannon instance painter)
    (when (is-shooting-p instance)
      (paint-shot instance painter))
    (unless (game-ended-p instance)
      (paint-target instance painter))
    (paint-barrier instance painter)
    (#_end painter)))

(defmethod mouse-press-event ((instance cannon-field) event)
  (setf (barrel-pressed-p instance)
        (and (enum= (#_button event) (#_LeftButton "Qt"))
             (barrel-hit-p instance (#_pos event)))))

(defmethod mouse-move-event ((instance cannon-field) event)
  (when (barrel-pressed-p instance)
    (let ((pos (#_pos event)))
      (unless (plusp (#_x pos))
        (#_setX pos 1))
      (unless (< (#_x pos) (#_height instance))
        (#_setX pos (1- (#_height instance))))
      (let ((radians (atan (- (float (#_bottom (#_rect instance)) 1.0d0)
                              (#_y pos))
                           (#_x pos))))
        (setf (current-angle instance)
              (round (* radians (/ 180 pi))))))))

(defmethod mouse-release-event ((instance cannon-field) event)
  (when (enum= (#_button event) (#_LeftButton "Qt"))
    (setf (barrel-pressed-p instance) nil)))

(defclass lcd-range ()
    ((slider :accessor slider)
     (label :accessor label))
  (:metaclass qt-class)
  (:qt-superclass "QWidget")
  (:slots ("setValue(int)" (lambda (this int) (setf (value this) int)))
          ("setRange(int,int)" set-range))
  (:signals ("valueChanged(int)")))

(defmethod value ((instance lcd-range))
  (#_value (slider instance)))

(defmethod (setf value) (newval (instance lcd-range))
  (#_setValue (slider instance) newval))

(defmethod text ((instance lcd-range))
  (#_text (label instance)))

(defmethod (setf text) (newval (instance lcd-range))
  (#_setText (label instance) newval))

(defun set-range (instance min max)
  (when (or (minusp min) (> max 99) (> min max))
    (warn "invalid SET-RANGE(~D, ~D)" min max))
  (#_setRange (slider instance) min max))

(defmethod initialize-instance
    :after
    ((instance lcd-range) &key parent text)
  (if parent
      (new instance parent)
      (new instance))
  (let ((lcd (#_new QLCDNumber 2)))
    (#_setSegmentStyle lcd (#_Filled "QLCDNumber"))
    (let ((slider (#_new QSlider (#_Horizontal "Qt"))))
      (setf (slider instance) slider)
      (#_setRange slider 0 99)
      (#_setValue slider 0)
      (connect slider "valueChanged(int)" lcd "display(int)")
      (connect slider "valueChanged(int)" instance "valueChanged(int)")
      (let ((label (#_new QLabel)))
        (#_setSizePolicy label
                         (#_Preferred "QSizePolicy")
                         (#_Fixed "QSizePolicy"))
        (setf (label instance) label)
        (#_setAlignment label (logior (enum-value
                                       (#_AlignHCenter "Qt"))
                                      (enum-value
                                       (#_AlignTop "Qt"))))
        (let ((layout (#_new QVBoxLayout)))
          (#_addWidget layout lcd)
          (#_addWidget layout slider)
          (#_addWidget layout label)
          (#_setLayout instance layout)))
      (#_setFocusProxy instance slider)))
  (when text
    (setf (text instance) text)))

(defclass game-board ()
    ((hits :accessor hits)
     (shots-left :accessor shots-left)
     (cannon-field :accessor cannon-field))
  (:metaclass qt-class)
  (:qt-superclass "QWidget")
  (:slots ("fire()" fire)
          ("hit()" hit)
          ("missed()" missed)
          ("newGame()" new-game)))

(defmethod initialize-instance :after ((instance game-board) &key parent)
  (if parent
      (new instance parent)
      (new instance))
  (with-objects ((font (#_new QFont "Times" 18 (#_Bold "QFont"))))
    (let ((quit (#_new QPushButton "&Quit"))
          (shoot (#_new QPushButton "&Shoot"))
          (new-game (#_new QPushButton "&New Game")))
      (#_setFont quit font)
      (#_setFont shoot font)
      (#_setFont new-game font)
      (connect new-game "clicked()" instance "newGame()")
      (connect quit "clicked()" *qapplication* "quit()")
      (let ((angle (make-instance 'lcd-range :text "ANGLE"))
            (force (make-instance 'lcd-range :text "FORCE"))
            (hits (#_new QLCDNumber 2))
            (shots-left (#_new QLCDNumber 2))
            (hits-label (#_new QLabel "HITS"))
            (shots-left-label (#_new QLabel "SHOTS LEFT"))
            (cf (make-instance 'cannon-field))
            (cannon-box (#_new QFrame)))
        (#_setFrameStyle cannon-box
                         (logior (enum-value (#_WinPanel "QFrame"))
                                 (enum-value (#_Sunken "QFrame"))))
        (with-objects ((key (#_new QKeySequence (#_Key_Enter "Qt"))))
          (#_new QShortcut key instance (QSLOT "fire()")))
        (with-objects ((key (#_new QKeySequence (#_Key_Return "Qt"))))
          (#_new QShortcut key instance (QSLOT "fire()")))
        (with-objects ((key (#_new QKeySequence (#_CTRL "Qt") (#_Key_Q "Qt"))))
          (#_new QShortcut key instance (QSLOT "close()")))
        (setf (cannon-field instance) cf)
        (setf (hits instance) hits)
        (setf (shots-left instance) shots-left)
        (#_setSegmentStyle hits (#_Filled "QLCDNumber"))
        (#_setSegmentStyle shots-left (#_Filled "QLCDNumber"))
        (connect shoot "clicked()" instance "fire()")
        (connect cf "hit()" instance "hit()")
        (connect cf "missed()" instance "missed()")
        (connect cf "canShoot(bool)" shoot "setEnabled(bool)")
        (set-range angle 5 70)
        (set-range force 10 50)
        (connect angle "valueChanged(int)" cf "setAngle(int)")
        (connect cf "angleChanged(int)" angle "setValue(int)")
        (connect force "valueChanged(int)" cf "setForce(int)")
        (connect cf "forceChanged(int)" force "setValue(int)")
        (let ((left-layout (#_new QVBoxLayout))
              (top-layout (#_new QHBoxLayout))
              (grid (#_new QGridLayout)))
          (#_addWidget left-layout angle)
          (#_addWidget left-layout force)

          (#_addWidget top-layout shoot)
          (#_addWidget top-layout hits)
          (#_addWidget top-layout hits-label)
          (#_addWidget top-layout shots-left)
          (#_addWidget top-layout shots-left-label)
          (#_addStretch top-layout 1)
          (#_addWidget top-layout new-game)

          (#_addWidget grid quit 0 0)
          (#_addLayout grid top-layout 0 1)
          (#_addLayout grid left-layout 1 0)
          (#_addWidget grid cannon-box 1 1 2 1)
          (#_addWidget grid cf 1 1 2 1)
          (#_setColumnStretch grid 1 10)
          (#_setLayout instance grid))
        (setf (value angle) 60)
        (setf (value force) 25)
        (#_setFocus angle)
        (new-game instance)))))

(defmethod fire ((game game-board))
  (with-slots (cannon-field shots-left) game
    (unless (or (game-ended-p cannon-field)
                (is-shooting-p cannon-field))
      (#_display shots-left (1- (#_intValue shots-left)))
      (shoot cannon-field))))

(defmethod hit ((game game-board))
  (with-slots (cannon-field hits shots-left) game
    (#_display hits (1+ (#_intValue hits)))
    (if (zerop (#_intValue shots-left))
        (set-game-over cannon-field)
        (new-target cannon-field))))

(defmethod missed ((game game-board))
  (with-slots (cannon-field shots-left) game
    (when (zerop (#_intValue shots-left))
      (set-game-over cannon-field))))

(defmethod new-game ((game game-board))
  (with-slots (cannon-field hits shots-left) game
    (#_display shots-left 15)
    (#_display hits 0)
    (restart-game cannon-field)
    (new-target cannon-field)))

(defun main ()
  (with-main-window (window (make-instance 'game-board))
    (#_setGeometry window 100 100 500 355)))
Is that seriously what lispers expect people to look at the first time they come to the library? whats worse is this does not have any information about how to make it work when the first time you try and run it it breaks.... I look at the commonQt site and none of what little documentation is there makes any sence at all in how to solve the problem of actually getting somthing to work.

How is anyone suposed to learn how to use the library if the examples do not work, the documentation seems to be written as clif-notes for someone who wrote the libary?

In other langauges & other applications. People - even open source guys write great tutorials - that work. There is extensive documentation. and many examples that work out of the box. There are talks on the internet - tutorials, classes. Thats totally missing with lisp. You have the 1986 mit videos for scheme on youtube. and there is the Algero videos. And some pakistan informataics course. Thtas about it. My question is why if its such a good language - why people don't take the time to try and expand the userbase? why write libraries that only the author can use efectively? why no write docs that are usefull other than clif-notes?

I just don't understand how whats suposed to be a largely academic-ivory-tower types can't get there heads around the need to teach - actually teach lisp to people. Is it some sort of bizare job security thing? I thought it was just random that so many people seem to be on islands developing everything they need for lisp themselves. But I came to see that you have no real other choice. Your sources of information are decades old videos and books. The libraries you try and use are no-longer suported - the only person that could tell you how they worked is no-longer contactable. The docs are either not their or like i said not intended for anyone who does not already know the library.

Image

pjstirling
Posts: 166
Joined: Sun Nov 28, 2010 4:21 pm

Re: clisp always seems to segfault when trying to do graphic

Post by pjstirling » Fri Oct 17, 2014 7:41 pm

It sounds like you've had a bad time of things :( There aren't a lot of people doing what you want to do, and that's the sort of code trail-blazing that gets called "bleeding-edge" for a reason. All of my lisp stuff is either command-line, or web-application interfaced, because those are known-quantities to me.

It's not purely lisp though, I tried to get a clojure-clr dev environment set up for windows this week and had to give up.

punchcard
Posts: 16
Joined: Fri Sep 26, 2014 5:50 pm

Re: clisp always seems to segfault when trying to do graphic

Post by punchcard » Fri Oct 17, 2014 8:44 pm

Thanks for your words fella .. always nice to hear from a person suffering along with you.

Lol I want to RTFM but there is no manual with most of these things. :lol:

I will make it work, I know it was done before so it can be done again. Lisp was ment to be a gui, like symbolics made. If they managed it more than 20 years ago I figure it can be done again today. (would be a lot of work but would be worth it - big payoff.) ncurses working properly and documented would be fantastic for clisp. Once I figure out how these binding libaries actually work I can get the jist of whats going on.

There are many parts left waiting to be completed from charms - its a big job and for one guy its understandable that a lot of it was not implemented. The commands are directly mapped from what I can tell. And if thats true I think I know what the problem with clisp might be - you got an interpreted langauge trying to manupulate a compiled forign library. If you screw that up as a user you are just going to get nasty errors from the outside. Lisp is not going to be able to help out much. Perhaps thats why the sbcl works better with some of the forign libraries because its doing the compiling under the hood.

In the mean time I will just generate ncurse files in c from lisp, tell sbcl or c to do the compile throuhg the shell - if theres errors wind down gracefully and get you to go back and edit. If that works then just get lisp to run the binaries, pipe the IO and do it that way. That should insulate lisp from the weird seg-faults from the forign libaries.

Its not an ideal solution but I think for the mean time it will work.

Qt is nice - thats a great solution for a modern gui. If only I could figure out how to make it work. :lol: Thats where it sucks - you have a powerfull and pretty straightforward tool thats been ported with next to no documentation. Obviously a lot of work went into making that happen but its got next to no documentation, and the examples are non-functional without some sort of hocus-pocus. That limits whos going to be able to use the library because at the moment how can you learn somthing that has little documentation/tutorials? I was watching the Qt Quick videos yesterday thinking to myself "How could they have made somthing so easy so difficult in lisp?"

Lisp is such a great language, it has so much potential. Discounting the issues with libaries I got so much stuff done that would have taken ages in C even python is like a straight jacket. Thats partly why I get frustrated with it - its been hamstrung with documentation issues, compatibility and outreach. But its not the end of the world. I would rather have a language that was like a beautiful pearl that was hampered by soft stuff or externals than a flawed language with a real good community/documentation. :lol: Ones salvageable - the other is forever flawed.

That said this forum is great - people are very supportive and do a lot to help people learn. Thats totally goes against what most people assume lispers to be. I figure once more people see that you can learn lisp without people jumping down your throat perhaps more would take up the language. 8-)

Not that its purely a lisp problem - imagine my suprise at getting my hands finaly on a copy of Advanced programming in the unix envoiroment 3rd edition.. same problem nothing compiles unless you use make on the orignal package. but try manually compiling any of the code and its broke. And thats the book everyone recomends - so you ask yourself who actually tried the examples?

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: clisp always seems to segfault when trying to do graphic

Post by Goheeca » Sat Oct 18, 2014 12:43 pm

Yeah, the libraries and docs are problem. :| However, with which problem are struggling right now, I've got Qt + CL working in windows and linux.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Post Reply