From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.user Subject: Re: GPT-4 knows Guile! :) Date: Fri, 17 Mar 2023 20:28:02 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000013cfb205f71d9491" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17334"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user , guile-devel To: mikael@djurfeldt.com Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Mar 17 20:29:10 2023 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pdFlF-0004FO-TR for guile-devel@m.gmane-mx.org; Fri, 17 Mar 2023 20:29:10 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdFkV-0006gW-0Z; Fri, 17 Mar 2023 15:28:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pdFkS-0006fl-LO; Fri, 17 Mar 2023 15:28:20 -0400 Original-Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdFkO-00073g-8U; Fri, 17 Mar 2023 15:28:20 -0400 Original-Received: by mail-ed1-x534.google.com with SMTP id er8so12668608edb.0; Fri, 17 Mar 2023 12:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679081294; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=snb05Qpk5lmX1uk3joZbVAeX047MtluKtLx5fqfSw94=; b=BBwRs6U+T2yyWC9Or4iyNKSM/syOJ3d+2TS51YqmmAqoifraPjG9B5+47WS5zKRhcA 2fCKlUWAAT6ePfRfFcPhTQhN1dKESFBqlwUygRPJqRPrWcgJPRK5C1w3kwfokyubeiHz A0u16m5rnC8WCE4etTOE06RU3x3aGsq8QucOEYdL1BPZsYN/OEglxZNzJoo+FAyhkG/O bejOSZJtkLihhcrpO7zMLdV3XTX3szDSH3TznfOrYZCUbxqXn2odIJdo2ld6erajKIuZ lI7X4Fo3pTU2B8NFDl2+mjidRYOUDPs5XTFFD3LXTLlbLtn4ku7udM1vSxmJPwOqb7v6 Kakg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679081294; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=snb05Qpk5lmX1uk3joZbVAeX047MtluKtLx5fqfSw94=; b=eiWuoc3J9Zel/f8dY+/dvbz76cg2+ijlwLp2JMdDKmH5gaWk4N9B/mdDixfEWSMIrE 6M4mhswd6p87sMohIIuD4auKHqk/n6J9aS4tdA/ZGLW3CPkolUu+WKVb/v7de7iMz5Zj R89GqHswp8vw263sOya4HrOH//HdgnTWJaKa4IdQGNS3l0TGTxA+0noSAeZxHRFQnzrE tchUWCOQ2p8oaXCQBFW9GSBFLB6mJ3+gVOKzeSc/KJqTcrF610dJB4s3ZO+Ap/izhAEh a7Io7vlCuLcJzq4PAA6t2V2NNFF8SV9bBgw8LakQGO9aZ7w60mF7fUJoG3wgmdDqDb3r D0xw== X-Gm-Message-State: AO0yUKWwLy7Z1MK6B4QBARStJ5uLwp5sGs5NynNFQaUJFjiX4e0/Wz7J 1FJK8xquSCvA3tO64aUm+BGEeCuN7clyPA8TeX5k15T22VM= X-Google-Smtp-Source: AK7set9OIZjPCywWwAnWVdmSJgiWy+UA/zmZr5CNQlEOs+J3bCb4tGADFOfxtZXfkNM1L+B7jPHLW3euFrrgSIJx7wo= X-Received: by 2002:a17:906:1b4e:b0:930:310:abcf with SMTP id p14-20020a1709061b4e00b009300310abcfmr255915ejg.2.1679081293990; Fri, 17 Mar 2023 12:28:13 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=damien.mattei@gmail.com; helo=mail-ed1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:21781 gmane.lisp.guile.user:18933 Archived-At: --00000000000013cfb205f71d9491 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable finally i can reconnect to chatGPT server and here is the result: (define (min-dnf expr) (let* ((vars (variables expr)) (truth-table (generate-truth-table vars)) (rows (filter (lambda (row) (eval expr (make-environment vars row))) truth-table)) (clauses (map (lambda (row) (create-clause vars row)) rows)) (dnf (fold-right or #f clauses))) (simplify dnf))) (define (variables expr) (let ((vars '())) (define (collect-variables exp) (cond ((symbol? exp) (unless (memq exp vars) (set! vars (cons exp vars)))) ((pair? exp) (map collect-variables exp)))) (collect-variables expr) vars)) (define (generate-truth-table vars) (let ((n (length vars))) (map (lambda (i) (list->vector (reverse (map (lambda (b) (if b 1 0)) (reverse (binary i n)))))) (range (expt 2 n))))) (define (binary n bits) (let loop ((n n) (bits bits) (acc '())) (if (zero? bits) acc (let ((bit (remainder n 2))) (loop (quotient n 2) (- bits 1) (cons bit acc)))))) (define (create-clause vars row) (let ((clause '())) (define (create-term var value) (if value var (cons 'not (list var)))) (map (lambda (pair) (set! clause (cons (create-term (car pair) (cdr pair)) clause))) (map cons vars row)) (reverse clause))) (define (make-environment vars row) (let ((env '())) (map (lambda (pair) (set! env (cons pair env))) (map cons vars row)) (reverse env))) (define (simplify expr) (let ((simp (simplify-expr expr))) (if (eq? expr simp) expr (simplify simp)))) (define (simplify-expr expr) (cond ((symbol? expr) expr) ((and (pair? expr) (eq? (car expr) 'not) (pair? (cdr expr))) (let ((arg (simplify-expr (cadr expr)))) (cond ((symbol? arg) (list 'not arg)) ((and (pair? arg) (eq? (car arg) 'not)) (simplify-expr (cadr arg))) (else (list 'not arg)))))) ((and (pair? expr) (memq (car expr) '(and or))) (let ((op (car expr)) (args (map simplify-expr (cdr expr)))) (let loop ((args args) (acc '())) (if (null? args) (if (eq? op 'and) #t (fold-right or #f acc)) (let ((arg (car args))) (if (eq? arg (if (eq? op 'and) #f #t)) (if (eq? op 'and) #f (fold-right or #f acc)) (loop (cdr args) (cons arg acc))))))))) (else expr))) ;;; /Users/mattei/chatGPTminimaldisjunctivenormalform.scm:6:26: source expression failed to match any pattern in form or ice-9/boot-9.scm:1685:16: In procedure raise-exception: Syntax error: unknown location: source expression failed to match any pattern in form or Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. and my conclusion is chatGPT is a very bad student that does not know the difference between a Scheme procedure and a special form :-) and the 65lines chatGPT code is far from my > 5000 lines code to minimize in disjunctive normal forms....... but you will continue to read a lot of newspaper saying AI is able to write programs.... chatGPT is only a "predictor of the next word" ,okay perheaps a bit more...= . On Fri, Mar 17, 2023 at 8:09=E2=80=AFPM Damien Mattei wrote: > i understand the fun thing... :-) > > and i did not check the program with Guile but asked a Racket version of > the bouncing ball and it is full of errors even if i try to correct them = by > hand... > > Welcome to DrRacket, version 8.7 [cs]. > Language: racket/gui, with debugging; memory limit: 8192 MB. > . . send: no such method > method name: register-event-callback > class name: canvas% > > > after i asked this question to chatGPT: > > "Can you write a Guile Scheme program that put a logical expression in > minimal disjunctive normal form?" > > i got a truncated program trying to code a QuineMcCluskey algorithm > implementation that i can not redisplay here because i got a connection > error to server and that looked like a bit,but from very very very far aw= ay > my own logic code in github that i spend many years to wrote, > > and the Chat finished like this: > > "Hmm...something seems to have gone wrong. Maybe try me again in a little > bit" > > :-) > > Damien > > On Fri, Mar 17, 2023 at 6:26=E2=80=AFPM Mikael Djurfeldt > wrote: > >> Can you write a Guile Scheme program which displays a bouncing ball? >> >> As an AI language model, I cannot create a full graphical program direct= ly >> within this text-based environment. However, I can provide you with an >> example of a simple bouncing ball simulation using the Guile Scheme >> programming language and the SDL2 (Simple DirectMedia Layer) library, >> which >> is commonly used for creating graphical applications. >> >> To start, you'll need to have Guile and the Guile-SDL2 bindings installe= d. >> The following instructions are for a Debian-based system: >> >> 1. Install Guile: >> >> csharp >> >> sudo apt-get install guile-2.2 >> >> >> 1. Install SDL2 development libraries: >> >> csharp >> >> sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev >> >> >> 1. Clone and build the Guile-SDL2 library: >> >> bash >> >> git clone https://github.com/davexunit/guile-sdl2.gitcd guile-sdl2 >> autoreconf -vif >> ./configure >> make >> sudo make install >> >> Now you can create the bouncing ball program in a file called >> bouncing-ball.scm: >> >> scheme >> >> (use-modules (sdl2) >> (sdl2 video) >> (sdl2 events) >> (sdl2 timer) >> (sdl2 rect)) >> >> (define screen-width 640) >> (define screen-height 480) >> (define ball-size 20) >> >> (define ball-x (make-parameter (/ (- screen-width ball-size) 2))) >> (define ball-y (make-parameter (/ (- screen-height ball-size) 2))) >> (define ball-x-velocity (make-parameter 4)) >> (define ball-y-velocity (make-parameter 4)) >> >> (define (process-events) >> (let loop ((event (poll-event))) >> (when event >> (case (event-type event) >> ((quit) #f) >> (else (loop (poll-event))))))) >> >> (define (update-ball) >> (parameterize ((x (ball-x)) >> (y (ball-y)) >> (vx (ball-x-velocity)) >> (vy (ball-y-velocity))) >> (ball-x (+ x vx)) >> (ball-y (+ y vy)) >> >> (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) screen-width)) >> (ball-x-velocity (- vx))) >> >> (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) screen-height)) >> (ball-y-velocity (- vy))))) >> >> (define (draw-ball renderer) >> (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size))) >> (set-render-draw-color renderer 255 0 0 255) >> (render-fill-rect renderer ball-rect))) >> >> (define (main) >> (init! +init-video+) >> (let ((window (create-window "Bouncing Ball" +window-pos-undefined+ >> +window-pos-undefined+ screen-width screen-height +window-shown+)) >> (renderer (create-renderer window -1 +renderer-accelerated+))) >> (set-render-draw-color renderer 0 0 0 255) >> (let loop () >> (unless (process-events) >> (update-ball) >> (render-clear renderer) >> (draw-ball renderer) >> (render-present renderer) >> (delay 16) >> (loop))))) >> >> (main) >> >> This example sets up a window using SDL2 and creates a simple ball that >> bounces off the edges of the window. You can run the program using the >> following command: >> >> bash >> >> guile bouncing-ball.scm >> >> Keep in mind that this is a simple example, and there are many ways to >> improve or expand upon it, such as using images >> [image: mikael@djurfeldt.com] >> I get the following error message: ;;; note: auto-compilation is enabled= , >> set GUILE_AUTO_COMPILE=3D0 ;;; or pass the --no-auto-compile argument to >> disable. ;;; compiling /home/mdj/guile/bouncing-ball.scm ;;; >> /home/mdj/guile/bouncing-ball.scm:19:13: warning: possibly unbound >> variable >> `event-type' ;;; /home/mdj/guile/bouncing-ball.scm:24:18: warning: >> possibly >> unbound variable `x' ;;; /home/mdj/guile/bouncing-ball.scm:25:18: warnin= g: >> possibly unbound variable `y' ;;; /home/mdj/guile/bouncing-ball.scm:26:1= 8: >> warning: possibly unbound variable `vx' ;;; >> /home/mdj/guile/bouncing-ball.scm:27:18: warning: possibly unbound >> variable >> `vy' ;;; /home/mdj/guile/bouncing-ball.scm:39:5: warning: possibly unbou= nd >> variable `set-render-draw-color' ;;; >> /home/mdj/guile/bouncing-ball.scm:40:5: warning: possibly unbound variab= le >> `render-fill-rect' ;;; /home/mdj/guile/bouncing-ball.scm:43:3: warning: >> possibly unbound variable `init!' ;;; >> /home/mdj/guile/bouncing-ball.scm:43:9: warning: possibly unbound variab= le >> `+init-video+' ;;; /home/mdj/guile/bouncing-ball.scm:44:17: warning: >> possibly unbound variable `create-window' ;;; >> /home/mdj/guile/bouncing-ball.scm:44:47: warning: possibly unbound >> variable >> `+window-pos-undefined+' ;;; /home/mdj/guile/bouncing-ball.scm:44:120: >> warning: possibly unbound variable `+window-shown+' ;;; >> /home/mdj/guile/bouncing-ball.scm:45:19: warning: possibly unbound >> variable >> `create-renderer' ;;; /home/mdj/guile/bouncing-ball.scm:45:35: warning: >> possibly unbound variable `window' ;;; >> /home/mdj/guile/bouncing-ball.scm:45:45: warning: possibly unbound >> variable >> `+renderer-accelerated+' ;;; /home/mdj/guile/bouncing-ball.scm:50:9: >> warning: possibly unbound variable `render-clear' ;;; >> /home/mdj/guile/bouncing-ball.scm:52:9: warning: possibly unbound variab= le >> `render-present' ;;; compiled >> >> /home/mdj/.cache/guile/ccache/3.0-LE-8-4.6/home/mdj/guile/bouncing-ball.= scm.go >> Backtrace: In ice-9/boot-9.scm: 1752:10 6 (with-exception-handler _ _ >> #:unwind? _ # _) In unknown file: 5 (apply-smob/0 #) >> In >> ice-9/boot-9.scm: 724:2 4 (call-with-prompt _ _ #> default-prompt-handle=E2=80=A6>) In ice-9/eval.scm: 619:8 3 (_ #(#(#> (guile-user) 7f79f1cdbc80>))) In ice-9/boot-9.scm: 2836:4 2 >> (save-module-excursion _) 4388:12 1 (_) In >> /home/mdj/guile/bouncing-ball.scm: 43:3 0 (main) >> /home/mdj/guile/bouncing-ball.scm:43:3: In procedure main: Unbound >> variable: init! >> >> Apologies for the confusion. It seems I made a mistake in the provided >> code, and some symbols were not correctly imported. Let's fix the import= s >> by using the appropriate modules and functions. Replace the (use-modules >> ...) line in the code with the following: >> >> scheme >> >> (use-modules (sdl2) (sdl2 video) (sdl2 events) (sdl2 timer) (sdl2 >> rect) (sdl2 rwops) (sdl2 surface) (sdl2 sdl)) >> >> Additionally, it seems that the init! function is not being recognized. = It >> should be SDL_Init instead. So, replace the line (init! +init-video+) >> with: >> >> scheme >> >> (SDL_Init +SDL_INIT_VIDEO+) >> >> After making these changes, the updated bouncing-ball.scm should look li= ke >> this: >> >> scheme >> >> (use-modules (sdl2) >> (sdl2 video) >> (sdl2 events) >> (sdl2 timer) >> (sdl2 rect) >> (sdl2 rwops) >> (sdl2 surface) >> (sdl2 sdl)) >> >> (define screen-width 640) >> (define screen-height 480) >> (define ball-size 20) >> >> (define ball-x (make-parameter (/ (- screen-width ball-size) 2))) >> (define ball-y (make-parameter (/ (- screen-height ball-size) 2))) >> (define ball-x-velocity (make-parameter 4)) >> (define ball-y-velocity (make-parameter 4)) >> >> (define (process-events) >> (let loop ((event (poll-event))) >> (when event >> (case (event-type event) >> ((quit) #f) >> (else (loop (poll-event))))))) >> >> (define (update-ball) >> (parameterize ((x (ball-x)) >> (y (ball-y)) >> (vx (ball-x-velocity)) >> (vy (ball-y-velocity))) >> (ball-x (+ x vx)) >> (ball-y (+ y vy)) >> >> (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) screen-width)) >> (ball-x-velocity (- vx))) >> >> (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) screen-height)) >> (ball-y-velocity (- vy))))) >> >> (define (draw-ball renderer) >> (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size))) >> (set-render-draw-color renderer 255 0 0 255) >> (render-fill-rect renderer ball-rect))) >> >> (define (main) >> (SDL_Init +SDL_INIT_VIDEO+) >> (let ((window (create-window "Bouncing Ball" +window-pos-undefined+ >> +window-pos-undefined+ screen-width screen-height +window-shown+)) >> (renderer (create-renderer window -1 +renderer-accelerated+))) >> (set-render-draw-color renderer 0 0 0 255) >> (let loop () >> (unless (process-events) >> (update-ball) >> (render-clear renderer) >> (draw-ball renderer) >> (render-present renderer) >> (delay 16) >> (loop))))) >> >> (main) >> >> Now, the program should run without any issues. Run it with: >> >> bash >> >> guile bouncing-ball.scm >> >> [image: mikael@djurfeldt.com] >> I think it should be make-window instead of create-window. >> >> You are correct. The function should be make-window instead of >> create-window. >> I apologize for the confusion. Here's the updated bouncing-ball.scm code >> with the corrected function name: >> >> scheme >> >> (use-modules (sdl2) >> (sdl2 video) >> (sdl2 events) >> (sdl2 timer) >> (sdl2 rect) >> (sdl2 rwops) >> (sdl2 surface) >> (sdl2 sdl)) >> >> (define screen-width 640) >> (define screen-height 480) >> (define ball-size 20) >> >> (define ball-x (make-parameter (/ (- screen-width ball-size) 2))) >> (define ball-y (make-parameter (/ (- screen-height ball-size) 2))) >> (define ball-x-velocity (make-parameter 4)) >> (define ball-y-velocity (make-parameter 4)) >> >> (define (process-events) >> (let loop ((event (poll-event))) >> (when event >> (case (event-type event) >> ((quit) #f) >> (else (loop (poll-event))))))) >> >> (define (update-ball) >> (parameterize ((x (ball-x)) >> (y (ball-y)) >> (vx (ball-x-velocity)) >> (vy (ball-y-velocity))) >> (ball-x (+ x vx)) >> (ball-y (+ y vy)) >> >> (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) screen-width)) >> (ball-x-velocity (- vx))) >> >> (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) screen-height)) >> (ball-y-velocity (- vy))))) >> >> (define (draw-ball renderer) >> (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size))) >> (set-render-draw-color renderer 255 0 0 255) >> (render-fill-rect renderer ball-rect))) >> >> (define (main) >> (SDL_Init +SDL_INIT_VIDEO+) >> (let ((window (make-window "Bouncing Ball" +window-pos-undefined+ >> +window-pos-undefined+ screen-width screen-height +window-shown+)) >> (renderer (create-renderer window -1 +renderer-accelerated+))) >> (set-render-draw-color renderer 0 0 0 255) >> (let loop () >> (unless (process-events) >> (update-ball) >> (render-clear renderer) >> (draw-ball renderer) >> (render-present renderer) >> (delay 16) >> (loop))))) >> >> (main) >> >> Now, the program should run as expected: >> >> bash >> >> guile bouncing-ball.scm >> >> [image: mikael@djurfeldt.com] >> Please write the program according to the guile-sdl2 manual. >> >> Apologies for the confusion. Here's an updated version of the bouncing >> ball >> program according to the guile-sdl2 manual: >> >> scheme >> >> (use-modules (sdl2) >> (sdl2 video) >> (sdl2 events) >> (sdl2 timer) >> (sdl2 rect) >> (sdl2 rwops) >> (sdl2 surface) >> (sdl2 sdl)) >> >> (define screen-width 640) >> (define screen-height 480) >> (define ball-size 20) >> >> (define ball-x (make-parameter (/ (- screen-width ball-size) 2))) >> (define ball-y (make-parameter (/ (- screen-height ball-size) 2))) >> (define ball-x-velocity (make-parameter 4)) >> (define ball-y-velocity (make-parameter 4)) >> >> (define (process-events) >> (let loop ((event (SDL_PollEvent))) >> (when event >> (case (event-type event) >> ((quit) #f) >> (else (loop (SDL_PollEvent))))))) >> >> (define (update-ball) >> (parameterize ((x (ball-x)) >> (y (ball-y)) >> (vx (ball-x-velocity)) >> (vy (ball-y-velocity))) >> (ball-x (+ x vx)) >> (ball-y (+ y vy)) >> >> (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) screen-width)) >> (ball-x-velocity (- vx))) >> >> (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) screen-height)) >> (ball-y-velocity (- vy))))) >> >> (define (draw-ball renderer) >> (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size))) >> (SDL_SetRenderDrawColor renderer 255 0 0 255) >> (SDL_RenderFillRect renderer ball-rect))) >> >> (define (main) >> (SDL_Init +SDL_INIT_VIDEO+) >> (let ((window (SDL_CreateWindow "Bouncing Ball" >> +SDL_WINDOWPOS_UNDEFINED+ +SDL_WINDOWPOS_UNDEFINED+ screen-width >> screen-height +SDL_WINDOW_SHOWN+)) >> (renderer (SDL_CreateRenderer window -1 >> +SDL_RENDERER_ACCELERATED+))) >> (SDL_SetRenderDrawColor renderer 0 0 0 255) >> (let loop () >> (unless (process-events) >> (update-ball) >> (SDL_RenderClear renderer) >> (draw-ball renderer) >> (SDL_RenderPresent renderer) >> (SDL_Delay 16) >> (loop)) >> (SDL_DestroyRenderer renderer) >> (SDL_DestroyWindow window))) >> >> (SDL_Quit) >> (main) >> >> Now, the program should run as expected: >> >> bash >> >> guile bouncing-ball.scm >> >> [image: mikael@djurfeldt.com] >> But all those SDL_ calls look like C bindings. Please use guile-sdl2 >> bindings. >> >> I apologize for the confusion. Here's the bouncing ball program >> implemented >> using the Guile-SDL2 bindings: >> >> scheme >> >> (use-modules (sdl2) >> (sdl2 video) >> (sdl2 events) >> (sdl2 timer) >> (sdl2 rect) >> (sdl2 rwops) >> (sdl2 surface) >> (sdl2 sdl)) >> >> (define screen-width 640) >> (define screen-height 480) >> (define ball-size 20) >> >> (define ball-x (make-parameter (/ (- screen-width ball-size) 2))) >> (define ball-y (make-parameter (/ (- screen-height ball-size) 2))) >> (define ball-x-velocity (make-parameter 4)) >> (define ball-y-velocity (make-parameter 4)) >> >> (define (process-events) >> (let loop ((event (poll-event))) >> (when event >> (case (event-type event) >> ((quit) #f) >> (else (loop (poll-event))))))) >> >> (define (update-ball) >> (parameterize ((x (ball-x)) >> (y (ball-y)) >> (vx (ball-x-velocity)) >> (vy (ball-y-velocity))) >> (ball-x (+ x vx)) >> (ball-y (+ y vy)) >> >> (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) screen-width)) >> (ball-x-velocity (- vx))) >> >> (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) screen-height)) >> (ball-y-velocity (- vy))))) >> >> (define (draw-ball renderer) >> (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size))) >> (set-render-draw-color! renderer 255 0 0 255) >> (render-fill-rect! renderer ball-rect))) >> >> (define (main) >> (init! +init-video+) >> (let ((window (make-window "Bouncing Ball" +window-pos-undefined+ >> +window-pos-undefined+ screen-width screen-height +window-shown+)) >> (renderer (make-renderer window -1 +renderer-accelerated+))) >> (set-render-draw-color! renderer 0 0 0 255) >> (let loop () >> (unless (process-events) >> (update-ball) >> (render-clear! renderer) >> (draw-ball renderer) >> (render-present! renderer) >> (delay 16) >> (loop)) >> (destroy-renderer! renderer) >> (destroy-window! window))) >> >> (quit!) >> (main) >> >> Now, the program should run as expected: >> >> bash >> >> guile bouncing-ball.scm >> >> --- >> >> Turns out there are multiple problems with that program also. Here I >> (mikael) fixed a number of problems and actually *got* a bouncing >> ball. :) >> >> (use-modules (sdl2) >> (sdl2 video) >> (sdl2 events) >> ;(sdl2 timer) >> (sdl2 rect) >> ;(sdl2 rwops) >> (sdl2 surface) >> ;(sdl2 sdl) >> (sdl2 render)) >> >> (define screen-width 640) >> (define screen-height 480) >> (define ball-size 20) >> >> (define ball-x (make-parameter (/ (- screen-width ball-size) 2))) >> (define ball-y (make-parameter (/ (- screen-height ball-size) 2))) >> (define ball-x-velocity (make-parameter 4)) >> (define ball-y-velocity (make-parameter 4)) >> >> (define (process-events) >> (let loop ((event (poll-event))) >> (if event >> (cond >> ((quit-event? event) #t) >> (else (loop (poll-event)))) >> #f))) >> >> (define (update-ball) >> (let ((x (ball-x)) >> (y (ball-y)) >> (vx (ball-x-velocity)) >> (vy (ball-y-velocity))) >> (ball-x (+ x vx)) >> (ball-y (+ y vy)) >> >> (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) screen-width)) >> (ball-x-velocity (- vx))) >> >> (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) screen-height)) >> (ball-y-velocity (- vy))))) >> >> (define (draw-ball renderer) >> (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size))) >> (set-renderer-draw-color! renderer 255 0 0 255) >> (render-fill-rect renderer ball-rect))) >> >> (define (main) >> (sdl-init) >> (let* ((window (make-window #:title "Bouncing Ball" #:size (list >> screen-width screen-height))) >> (renderer (make-renderer window))) >> (set-renderer-draw-color! renderer 0 0 0 255) >> (let loop () >> (unless (process-events) >> (update-ball) >> (set-renderer-draw-color! renderer 0 0 0 0) >> (clear-renderer renderer) >> (draw-ball renderer) >> (present-renderer renderer) >> ;(delay 16) >> (loop)) >> (delete-renderer! renderer) >> ;(destroy-window! window) >> ))) >> >> ;(quit!) >> (main) >> > --00000000000013cfb205f71d9491 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
fin= ally i can reconnect to chatGPT server and here is the result:

(define (min-dnf expr)
=C2=A0 (let= * ((vars (variables expr))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(truth-tabl= e (generate-truth-table vars))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(rows (= filter (lambda (row) (eval expr (make-environment vars row))) truth-table))=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(clauses (map (lambda (row) (create-c= lause vars row)) rows))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(dnf (fold-rig= ht or #f clauses)))
=C2=A0 =C2=A0 (simplify dnf)))

(define (varia= bles expr)
=C2=A0 (let ((vars '()))
=C2=A0 =C2=A0 (define (collec= t-variables exp)
=C2=A0 =C2=A0 =C2=A0 (cond ((symbol? exp) (unless (memq= exp vars) (set! vars (cons exp vars))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 ((pair? exp) (map collect-variables exp))))
=C2=A0 =C2=A0 (co= llect-variables expr)
=C2=A0 =C2=A0 vars))

(define (generate-trut= h-table vars)
=C2=A0 (let ((n (length vars)))
=C2=A0 =C2=A0 (map (lam= bda (i) (list->vector (reverse (map (lambda (b) (if b 1 0))
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 (reverse (binary i n)))))) (range (expt 2 n)))))
(define (binary n bits)
=C2=A0 (let loop ((n n) (bits bits) (acc '= ()))
=C2=A0 =C2=A0 (if (zero? bits) acc
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (= let ((bit (remainder n 2)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (loop (qu= otient n 2) (- bits 1) (cons bit acc))))))

(define (create-clause va= rs row)
=C2=A0 (let ((clause '()))
=C2=A0 =C2=A0 (define (create-= term var value)
=C2=A0 =C2=A0 =C2=A0 (if value var (cons 'not (list = var))))
=C2=A0 =C2=A0 (map (lambda (pair) (set! clause (cons (create-ter= m (car pair) (cdr pair)) clause)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(ma= p cons vars row))
=C2=A0 =C2=A0 (reverse clause)))

(define (make-= environment vars row)
=C2=A0 (let ((env '()))
=C2=A0 =C2=A0 (map = (lambda (pair) (set! env (cons pair env)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(map cons vars row))
=C2=A0 =C2=A0 (reverse env)))

(define = (simplify expr)
=C2=A0 (let ((simp (simplify-expr expr)))
=C2=A0 =C2= =A0 (if (eq? expr simp) expr (simplify simp))))

(define (simplify-ex= pr expr)
=C2=A0 (cond ((symbol? expr) expr)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 ((and (pair? expr) (eq? (car expr) 'not) (pair? (cdr expr)))
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((arg (simplify-expr (cadr expr))))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cond ((symbol? arg) (list 'no= t arg))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0((= and (pair? arg) (eq? (car arg) 'not))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (simplify-expr (cadr arg)))
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(else (list 'not= arg))))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ((and (pair? expr) (memq (car exp= r) '(and or)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((op (car expr= ))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(args (map sim= plify-expr (cdr expr))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let l= oop ((args args) (acc '()))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(if (null? args)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(if (eq? op 'and) #t (fold-right or #f acc))
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((arg (car arg= s)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(if (eq? arg (if (eq? op 'and) #f #t))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if (eq? op '= ;and) #f (fold-right or #f acc))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(loop (cdr args) (cons arg acc= )))))))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (else expr)))

;;; /Users/mattei/chatGPTminimaldisjunctiveno= rmalform.scm:6:26: source expression failed to match any pattern in form or=
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Syntax error= :
unknown location: source expression failed to match any pattern in for= m or

Entering a new prompt.=C2=A0 Type `,bt' for a backtrace or = `,q' to continue.

and= my conclusion is chatGPT is a very bad student that does not know the diff= erence between a Scheme procedure and a special form :-)

and the 65lines chatGPT code is far from my= > 5000 lines code to minimize in disjunctive normal forms.......

but you will continue to r= ead a lot of newspaper saying AI is able to write programs....

chatGPT is only a "predictor of = the next word" ,okay perheaps a bit more....

On Fri, Mar 17, = 2023 at 8:09=E2=80=AFPM Damien Mattei <damien.mattei@gmail.com> wrote:
i understand the fun thing... :-)

and i did not check the program with= Guile but asked a Racket version of the bouncing ball and it is full of er= rors even if i try to correct them by hand...

Welcome to DrRacket, version 8.7 [cs].
Language: ra= cket/gui, with debugging; memory limit: 8192 MB.
. . send: no such metho= d
=C2=A0 method name: register-event-callback
=C2=A0 class name: canv= as%

<= div class=3D"gmail_default" style=3D"font-size:large">
after i asked this question to= chatGPT:

<= /div>
"Can you w= rite a Guile Scheme program that put a logical expression in minimal disjun= ctive normal form?"

i got a truncated program trying to code a QuineMcCluskey algorithm im= plementation that i can not redisplay here because i got a connection error= to server and that looked like a bit,but from very very very far away my o= wn logic code in github that i spend many years to wrote,

and the Chat finished=C2=A0 like this= :

"Hmm...something s= eems to have gone wrong. Maybe try me again in a little bit"

:-)

Damien

On Fri, Mar 17, 2023 at 6:26= =E2=80=AFPM Mikael Djurfeldt <mikael@djurfeldt.com> wrote:
Can you write a Guile Scheme program wh= ich displays a bouncing ball?

As an AI language model, I cannot create a full graphical program directly<= br> within this text-based environment. However, I can provide you with an
example of a simple bouncing ball simulation using the Guile Scheme
programming language and the SDL2 (Simple DirectMedia Layer) library, which=
is commonly used for creating graphical applications.

To start, you'll need to have Guile and the Guile-SDL2 bindings install= ed.
The following instructions are for a Debian-based system:

=C2=A0 =C2=A01. Install Guile:

csharp

sudo apt-get install guile-2.2


=C2=A0 =C2=A01. Install SDL2 development libraries:

csharp

sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev


=C2=A0 =C2=A01. Clone and build the Guile-SDL2 library:

bash

git clone https://github.com/davexunit/guile-sdl2.gitcd= guile-sdl2
autoreconf -vif
./configure
make
sudo make install

Now you can create the bouncing ball program in a file called
bouncing-ball.scm:

scheme

(use-modules (sdl2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 video)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 timer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 rect))

(define screen-width 640)
(define screen-height 480)
(define ball-size 20)

(define ball-x (make-parameter (/ (- screen-width ball-size) 2)))
(define ball-y (make-parameter (/ (- screen-height ball-size) 2)))
(define ball-x-velocity (make-parameter 4))
(define ball-y-velocity (make-parameter 4))

(define (process-events)
=C2=A0 (let loop ((event (poll-event)))
=C2=A0 =C2=A0 (when event
=C2=A0 =C2=A0 =C2=A0 (case (event-type event)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ((quit) #f)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (else (loop (poll-event)))))))

(define (update-ball)
=C2=A0 (parameterize ((x (ball-x))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(y (ball-y))<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(vx (ball-x-v= elocity))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(vy (ball-y-v= elocity)))
=C2=A0 =C2=A0 (ball-x (+ x vx))
=C2=A0 =C2=A0 (ball-y (+ y vy))

=C2=A0 =C2=A0 (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) sc= reen-width))
=C2=A0 =C2=A0 =C2=A0 (ball-x-velocity (- vx)))

=C2=A0 =C2=A0 (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) sc= reen-height))
=C2=A0 =C2=A0 =C2=A0 (ball-y-velocity (- vy)))))

(define (draw-ball renderer)
=C2=A0 (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size)))=
=C2=A0 =C2=A0 (set-render-draw-color renderer 255 0 0 255)
=C2=A0 =C2=A0 (render-fill-rect renderer ball-rect)))

(define (main)
=C2=A0 (init! +init-video+)
=C2=A0 (let ((window (create-window "Bouncing Ball" +window-pos-u= ndefined+
+window-pos-undefined+ screen-width screen-height +window-shown+))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (renderer (create-renderer window -1 +renderer-= accelerated+)))
=C2=A0 =C2=A0 (set-render-draw-color renderer 0 0 0 255)
=C2=A0 =C2=A0 (let loop ()
=C2=A0 =C2=A0 =C2=A0 (unless (process-events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (update-ball)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (render-clear renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (draw-ball renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (render-present renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (delay 16)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (loop)))))

(main)

This example sets up a window using SDL2 and creates a simple ball that
bounces off the edges of the window. You can run the program using the
following command:

bash

guile bouncing-ball.scm

Keep in mind that this is a simple example, and there are many ways to
improve or expand upon it, such as using images
[image: mikael@dj= urfeldt.com]
I get the following error message: ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=3D0 ;;; or pass the --no-auto-compile argument to disable. ;;; compiling /home/mdj/guile/bouncing-ball.scm ;;;
/home/mdj/guile/bouncing-ball.scm:19:13: warning: possibly unbound variable=
`event-type' ;;; /home/mdj/guile/bouncing-ball.scm:24:18: warning: poss= ibly
unbound variable `x' ;;; /home/mdj/guile/bouncing-ball.scm:25:18: warni= ng:
possibly unbound variable `y' ;;; /home/mdj/guile/bouncing-ball.scm:26:= 18:
warning: possibly unbound variable `vx' ;;;
/home/mdj/guile/bouncing-ball.scm:27:18: warning: possibly unbound variable=
`vy' ;;; /home/mdj/guile/bouncing-ball.scm:39:5: warning: possibly unbo= und
variable `set-render-draw-color' ;;;
/home/mdj/guile/bouncing-ball.scm:40:5: warning: possibly unbound variable<= br> `render-fill-rect' ;;; /home/mdj/guile/bouncing-ball.scm:43:3: warning:=
possibly unbound variable `init!' ;;;
/home/mdj/guile/bouncing-ball.scm:43:9: warning: possibly unbound variable<= br> `+init-video+' ;;; /home/mdj/guile/bouncing-ball.scm:44:17: warning: possibly unbound variable `create-window' ;;;
/home/mdj/guile/bouncing-ball.scm:44:47: warning: possibly unbound variable=
`+window-pos-undefined+' ;;; /home/mdj/guile/bouncing-ball.scm:44:120:<= br> warning: possibly unbound variable `+window-shown+' ;;;
/home/mdj/guile/bouncing-ball.scm:45:19: warning: possibly unbound variable=
`create-renderer' ;;; /home/mdj/guile/bouncing-ball.scm:45:35: warning:=
possibly unbound variable `window' ;;;
/home/mdj/guile/bouncing-ball.scm:45:45: warning: possibly unbound variable=
`+renderer-accelerated+' ;;; /home/mdj/guile/bouncing-ball.scm:50:9: warning: possibly unbound variable `render-clear' ;;;
/home/mdj/guile/bouncing-ball.scm:52:9: warning: possibly unbound variable<= br> `render-present' ;;; compiled
/home/mdj/.cache/guile/ccache/3.0-LE-8-4.6/home/mdj/guile/bouncing-ball.scm= .go
Backtrace: In ice-9/boot-9.scm: 1752:10 6 (with-exception-handler _ _
#:unwind? _ # _) In unknown file: 5 (apply-smob/0 #<thunk 7f79f1cd8300&g= t;) In
ice-9/boot-9.scm: 724:2 4 (call-with-prompt _ _ #<procedure
default-prompt-handle=E2=80=A6>) In ice-9/eval.scm: 619:8 3 (_ #(#(#<= directory
(guile-user) 7f79f1cdbc80>))) In ice-9/boot-9.scm: 2836:4 2
(save-module-excursion _) 4388:12 1 (_) In
/home/mdj/guile/bouncing-ball.scm: 43:3 0 (main)
/home/mdj/guile/bouncing-ball.scm:43:3: In procedure main: Unbound
variable: init!

Apologies for the confusion. It seems I made a mistake in the provided
code, and some symbols were not correctly imported. Let's fix the impor= ts
by using the appropriate modules and functions. Replace the (use-modules ...) line in the code with the following:

scheme

(use-modules (sdl2) (sdl2 video) (sdl2 events) (sdl2 timer) (sdl2
rect) (sdl2 rwops) (sdl2 surface) (sdl2 sdl))

Additionally, it seems that the init! function is not being recognized. It<= br> should be SDL_Init instead. So, replace the line (init! +init-video+) with:=

scheme

(SDL_Init +SDL_INIT_VIDEO+)

After making these changes, the updated bouncing-ball.scm should look like<= br> this:

scheme

(use-modules (sdl2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 video)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 timer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 rect)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 rwops)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 surface)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 sdl))

(define screen-width 640)
(define screen-height 480)
(define ball-size 20)

(define ball-x (make-parameter (/ (- screen-width ball-size) 2)))
(define ball-y (make-parameter (/ (- screen-height ball-size) 2)))
(define ball-x-velocity (make-parameter 4))
(define ball-y-velocity (make-parameter 4))

(define (process-events)
=C2=A0 (let loop ((event (poll-event)))
=C2=A0 =C2=A0 (when event
=C2=A0 =C2=A0 =C2=A0 (case (event-type event)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ((quit) #f)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (else (loop (poll-event)))))))

(define (update-ball)
=C2=A0 (parameterize ((x (ball-x))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(y (ball-y))<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(vx (ball-x-v= elocity))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(vy (ball-y-v= elocity)))
=C2=A0 =C2=A0 (ball-x (+ x vx))
=C2=A0 =C2=A0 (ball-y (+ y vy))

=C2=A0 =C2=A0 (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) sc= reen-width))
=C2=A0 =C2=A0 =C2=A0 (ball-x-velocity (- vx)))

=C2=A0 =C2=A0 (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) sc= reen-height))
=C2=A0 =C2=A0 =C2=A0 (ball-y-velocity (- vy)))))

(define (draw-ball renderer)
=C2=A0 (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size)))=
=C2=A0 =C2=A0 (set-render-draw-color renderer 255 0 0 255)
=C2=A0 =C2=A0 (render-fill-rect renderer ball-rect)))

(define (main)
=C2=A0 (SDL_Init +SDL_INIT_VIDEO+)
=C2=A0 (let ((window (create-window "Bouncing Ball" +window-pos-u= ndefined+
+window-pos-undefined+ screen-width screen-height +window-shown+))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (renderer (create-renderer window -1 +renderer-= accelerated+)))
=C2=A0 =C2=A0 (set-render-draw-color renderer 0 0 0 255)
=C2=A0 =C2=A0 (let loop ()
=C2=A0 =C2=A0 =C2=A0 (unless (process-events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (update-ball)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (render-clear renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (draw-ball renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (render-present renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (delay 16)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (loop)))))

(main)

Now, the program should run without any issues. Run it with:

bash

guile bouncing-ball.scm

[image: mikael@dj= urfeldt.com]
I think it should be make-window instead of create-window.

You are correct. The function should be make-window instead of create-windo= w.
I apologize for the confusion. Here's the updated bouncing-ball.scm cod= e
with the corrected function name:

scheme

(use-modules (sdl2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 video)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 timer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 rect)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 rwops)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 surface)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 sdl))

(define screen-width 640)
(define screen-height 480)
(define ball-size 20)

(define ball-x (make-parameter (/ (- screen-width ball-size) 2)))
(define ball-y (make-parameter (/ (- screen-height ball-size) 2)))
(define ball-x-velocity (make-parameter 4))
(define ball-y-velocity (make-parameter 4))

(define (process-events)
=C2=A0 (let loop ((event (poll-event)))
=C2=A0 =C2=A0 (when event
=C2=A0 =C2=A0 =C2=A0 (case (event-type event)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ((quit) #f)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (else (loop (poll-event)))))))

(define (update-ball)
=C2=A0 (parameterize ((x (ball-x))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(y (ball-y))<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(vx (ball-x-v= elocity))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(vy (ball-y-v= elocity)))
=C2=A0 =C2=A0 (ball-x (+ x vx))
=C2=A0 =C2=A0 (ball-y (+ y vy))

=C2=A0 =C2=A0 (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) sc= reen-width))
=C2=A0 =C2=A0 =C2=A0 (ball-x-velocity (- vx)))

=C2=A0 =C2=A0 (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) sc= reen-height))
=C2=A0 =C2=A0 =C2=A0 (ball-y-velocity (- vy)))))

(define (draw-ball renderer)
=C2=A0 (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size)))=
=C2=A0 =C2=A0 (set-render-draw-color renderer 255 0 0 255)
=C2=A0 =C2=A0 (render-fill-rect renderer ball-rect)))

(define (main)
=C2=A0 (SDL_Init +SDL_INIT_VIDEO+)
=C2=A0 (let ((window (make-window "Bouncing Ball" +window-pos-und= efined+
+window-pos-undefined+ screen-width screen-height +window-shown+))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (renderer (create-renderer window -1 +renderer-= accelerated+)))
=C2=A0 =C2=A0 (set-render-draw-color renderer 0 0 0 255)
=C2=A0 =C2=A0 (let loop ()
=C2=A0 =C2=A0 =C2=A0 (unless (process-events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (update-ball)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (render-clear renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (draw-ball renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (render-present renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (delay 16)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (loop)))))

(main)

Now, the program should run as expected:

bash

guile bouncing-ball.scm

[image: mikael@dj= urfeldt.com]
Please write the program according to the guile-sdl2 manual.

Apologies for the confusion. Here's an updated version of the bouncing = ball
program according to the guile-sdl2 manual:

scheme

(use-modules (sdl2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 video)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 timer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 rect)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 rwops)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 surface)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 sdl))

(define screen-width 640)
(define screen-height 480)
(define ball-size 20)

(define ball-x (make-parameter (/ (- screen-width ball-size) 2)))
(define ball-y (make-parameter (/ (- screen-height ball-size) 2)))
(define ball-x-velocity (make-parameter 4))
(define ball-y-velocity (make-parameter 4))

(define (process-events)
=C2=A0 (let loop ((event (SDL_PollEvent)))
=C2=A0 =C2=A0 (when event
=C2=A0 =C2=A0 =C2=A0 (case (event-type event)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ((quit) #f)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (else (loop (SDL_PollEvent)))))))

(define (update-ball)
=C2=A0 (parameterize ((x (ball-x))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(y (ball-y))<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(vx (ball-x-v= elocity))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(vy (ball-y-v= elocity)))
=C2=A0 =C2=A0 (ball-x (+ x vx))
=C2=A0 =C2=A0 (ball-y (+ y vy))

=C2=A0 =C2=A0 (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) sc= reen-width))
=C2=A0 =C2=A0 =C2=A0 (ball-x-velocity (- vx)))

=C2=A0 =C2=A0 (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) sc= reen-height))
=C2=A0 =C2=A0 =C2=A0 (ball-y-velocity (- vy)))))

(define (draw-ball renderer)
=C2=A0 (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size)))=
=C2=A0 =C2=A0 (SDL_SetRenderDrawColor renderer 255 0 0 255)
=C2=A0 =C2=A0 (SDL_RenderFillRect renderer ball-rect)))

(define (main)
=C2=A0 (SDL_Init +SDL_INIT_VIDEO+)
=C2=A0 (let ((window (SDL_CreateWindow "Bouncing Ball"
+SDL_WINDOWPOS_UNDEFINED+ +SDL_WINDOWPOS_UNDEFINED+ screen-width
screen-height +SDL_WINDOW_SHOWN+))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (renderer (SDL_CreateRenderer window -1 +SDL_RE= NDERER_ACCELERATED+)))
=C2=A0 =C2=A0 (SDL_SetRenderDrawColor renderer 0 0 0 255)
=C2=A0 =C2=A0 (let loop ()
=C2=A0 =C2=A0 =C2=A0 (unless (process-events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (update-ball)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (SDL_RenderClear renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (draw-ball renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (SDL_RenderPresent renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (SDL_Delay 16)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (loop))
=C2=A0 =C2=A0 (SDL_DestroyRenderer renderer)
=C2=A0 =C2=A0 (SDL_DestroyWindow window)))

(SDL_Quit)
(main)

Now, the program should run as expected:

bash

guile bouncing-ball.scm

[image: mikael@dj= urfeldt.com]
But all those SDL_ calls look like C bindings. Please use guile-sdl2
bindings.

I apologize for the confusion. Here's the bouncing ball program impleme= nted
using the Guile-SDL2 bindings:

scheme

(use-modules (sdl2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 video)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 timer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 rect)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 rwops)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 surface)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 sdl))

(define screen-width 640)
(define screen-height 480)
(define ball-size 20)

(define ball-x (make-parameter (/ (- screen-width ball-size) 2)))
(define ball-y (make-parameter (/ (- screen-height ball-size) 2)))
(define ball-x-velocity (make-parameter 4))
(define ball-y-velocity (make-parameter 4))

(define (process-events)
=C2=A0 (let loop ((event (poll-event)))
=C2=A0 =C2=A0 (when event
=C2=A0 =C2=A0 =C2=A0 (case (event-type event)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ((quit) #f)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (else (loop (poll-event)))))))

(define (update-ball)
=C2=A0 (parameterize ((x (ball-x))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(y (ball-y))<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(vx (ball-x-v= elocity))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(vy (ball-y-v= elocity)))
=C2=A0 =C2=A0 (ball-x (+ x vx))
=C2=A0 =C2=A0 (ball-y (+ y vy))

=C2=A0 =C2=A0 (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) sc= reen-width))
=C2=A0 =C2=A0 =C2=A0 (ball-x-velocity (- vx)))

=C2=A0 =C2=A0 (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) sc= reen-height))
=C2=A0 =C2=A0 =C2=A0 (ball-y-velocity (- vy)))))

(define (draw-ball renderer)
=C2=A0 (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size)))=
=C2=A0 =C2=A0 (set-render-draw-color! renderer 255 0 0 255)
=C2=A0 =C2=A0 (render-fill-rect! renderer ball-rect)))

(define (main)
=C2=A0 (init! +init-video+)
=C2=A0 (let ((window (make-window "Bouncing Ball" +window-pos-und= efined+
+window-pos-undefined+ screen-width screen-height +window-shown+))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (renderer (make-renderer window -1 +renderer-ac= celerated+)))
=C2=A0 =C2=A0 (set-render-draw-color! renderer 0 0 0 255)
=C2=A0 =C2=A0 (let loop ()
=C2=A0 =C2=A0 =C2=A0 (unless (process-events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (update-ball)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (render-clear! renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (draw-ball renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (render-present! renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (delay 16)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (loop))
=C2=A0 =C2=A0 (destroy-renderer! renderer)
=C2=A0 =C2=A0 (destroy-window! window)))

(quit!)
(main)

Now, the program should run as expected:

bash

guile bouncing-ball.scm

---

Turns out there are multiple problems with that program also. Here I
(mikael) fixed a number of problems and actually *got* a bouncing
ball. :)

(use-modules (sdl2)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 video)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;(sdl2 timer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 rect)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;(sdl2 rwops)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 surface)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;(sdl2 s= dl)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(sdl2 render))

(define screen-width 640)
(define screen-height 480)
(define ball-size 20)

(define ball-x (make-parameter (/ (- screen-width ball-size) 2)))
(define ball-y (make-parameter (/ (- screen-height ball-size) 2)))
(define ball-x-velocity (make-parameter 4))
(define ball-y-velocity (make-parameter 4))

(define (process-events)
=C2=A0 (let loop ((event (poll-event)))
=C2=A0 =C2=A0 (if event
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (cond
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0((quit-event? event) #t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(else (loop (poll-event))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 #f)))

(define (update-ball)
=C2=A0 (let ((x (ball-x))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (y (ball-y))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (vx (ball-x-velocity))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (vy (ball-y-velocity)))
=C2=A0 =C2=A0 (ball-x (+ x vx))
=C2=A0 =C2=A0 (ball-y (+ y vy))

=C2=A0 =C2=A0 (when (or (<=3D (+ x vx) 0) (>=3D (+ x vx ball-size) sc= reen-width))
=C2=A0 =C2=A0 =C2=A0 (ball-x-velocity (- vx)))

=C2=A0 =C2=A0 (when (or (<=3D (+ y vy) 0) (>=3D (+ y vy ball-size) sc= reen-height))
=C2=A0 =C2=A0 =C2=A0 (ball-y-velocity (- vy)))))

(define (draw-ball renderer)
=C2=A0 (let ((ball-rect (make-rect (ball-x) (ball-y) ball-size ball-size)))=
=C2=A0 =C2=A0 (set-renderer-draw-color! renderer 255 0 0 255)
=C2=A0 =C2=A0 (render-fill-rect renderer ball-rect)))

(define (main)
=C2=A0 (sdl-init)
=C2=A0 (let* ((window (make-window #:title "Bouncing Ball" #:size= (list
screen-width screen-height)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(renderer (make-renderer window)))
=C2=A0 =C2=A0 (set-renderer-draw-color! renderer 0 0 0 255)
=C2=A0 =C2=A0 (let loop ()
=C2=A0 =C2=A0 =C2=A0 (unless (process-events)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (update-ball)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (set-renderer-draw-color! renderer 0 0 0 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (clear-renderer renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (draw-ball renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (present-renderer renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;(delay = 16)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (loop))
=C2=A0 =C2=A0 (delete-renderer! renderer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;(destro= y-window! window)
=C2=A0 =C2=A0 )))

;(quit!)
(main)
--00000000000013cfb205f71d9491--