<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title>GNUcode.me</title><id>https://gnucode.me/feeds/tags/guile scheme.xml</id><subtitle>Tag: guile scheme</subtitle><updated>2024-04-18T01:18:57Z</updated><link href="https://gnucode.me/feeds/tags/guile scheme.xml" rel="self" /><link href="https://gnucode.me" /><entry><title>The Power of Scheme</title><id>https://gnucode.me/the-power-of-scheme.html</id><author><name>Joshua Branson</name><email>jbranso@dismail.de</email></author><updated>2021-01-22T22:00:00Z</updated><link href="https://gnucode.me/the-power-of-scheme.html" rel="alternate" /><content type="html">&lt;p&gt;I am currently building a sway service for GNU Guix.  Some of the videos for
that are
&lt;a href=&quot;https://video.hardlimit.com/my-account/video-playlists/06baf279-76ea-406a-a24d-2fcfefecbf35&quot;&gt;here.&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The following blog post is going to show one recent mental goof I had recently.
Please bear in mind, that I am still learning scheme, and what I am saying is an
attempt to think out loud (thought-vomit) and may not reflect reality.  This is
an attempt to clarify my thoughts and better understand scheme, particularly GNU
Guile.&lt;/p&gt;&lt;p&gt;Consider this simplified scheme function (the original used &lt;code&gt;match-lambda&lt;/code&gt;).&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-scheme&quot;&gt;(define (proc x)
   (lambda (x)
      (display x)))&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A beginner scheme programmer (like me), would look at this procedure and assume
that there is &lt;em&gt;no correct&lt;/em&gt; way to call this procedure.  For example:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-scheme&quot;&gt;(proc &amp;quot;Hello World\n&amp;quot;) ;; compiles and runs but does not display Hello World.

(proc)  ;; This creates a compile error

((proc &amp;quot;Hello World&amp;quot;))  ;; This create a compile error&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So I decided to try to be helpful.  If Guile compiles the first line of code,
but it &lt;em&gt;cannot&lt;/em&gt; run correctly, then why compile it? So I filed a bug report with
&lt;a href=&quot;http://issues.guix.gnu.org/46014&quot;&gt;GNU Guile developers&lt;/a&gt;.  (The GNU Guile devs
are fantastic people by the way.  We actually had a pretty cool exchange back
and forth).  Well, it turns out that the correct way to call the above procedure
is this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-scheme&quot;&gt;((proc &amp;lt;whatever value you want here&amp;gt;) &amp;quot;Hello World&amp;quot;)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Essentially the above &lt;code&gt;proc&lt;/code&gt; is the same thing as this:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-scheme&quot;&gt;(define proc
  (lambda (x)
    (lambda (x)
      x)))&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So &lt;code&gt;proc&lt;/code&gt; is a procedure that takes one argument, and returns a procedure that
takes one argument.  The two &lt;code&gt;x&lt;/code&gt;s there are not related.  One should probably
write the above procedure as:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-scheme&quot;&gt;(define proc
  (lambda (x)
    (lambda (y)
      y)))&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This hopefully shows that &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; are two different values.&lt;/p&gt;&lt;p&gt;Occasionally as I am writing GNU Guile code, Guile will tell me that an error
occurred, but fail to report the error line number.  I suspect that has to do
with macro shenanigans.  Just today I discovered such an error and made a commit
with it
&lt;a href=&quot;https://notabug.org/jbranso/guix/commit/7a003d066c2bf09370f8196651f82e636bfae0aa&quot;&gt;here&lt;/a&gt;,
so that later I can simplify that file down to its bare essentials, and submit
another guile report or talk to some guile people about it.&lt;/p&gt;&lt;p&gt;Here is the error in a simplified form:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;language-scheme&quot;&gt;(use-modules (guix records))

(define-record-type* &amp;lt;sway-bindsym&amp;gt;
  sway-bindsym make-sway-bindsym
  sway-bindsym?
  (key-combo sway-bindsym-key-combo
             (default &amp;quot;&amp;quot;)))

(display sway-bindsym)  ;; compile error at unknown location&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here is the compile error output:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;;;; note: source file /home/joshua/prog/guile/test.scm
;;;       newer than compiled /home/joshua/.cache/guile/ccache/3.0-LE-8-4.4/home/joshua/prog/guile/test.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/joshua/prog/guile/test.scm
;;; WARNING: compilation of /home/joshua/prog/guile/test.scm failed:
;;; Syntax error:
;;; unknown location: source expression failed to match any pattern in form sway-bindsym
ice-9/psyntax.scm:2800:12: In procedure syntax-violation:
Syntax error:
unknown location: source expression failed to match any pattern in form sway-bindsym&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;What I needed to type at that last line was:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;(display (sway-bindsym)) ;; correct&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;(sway-bindsym)&lt;/code&gt; is a macro that I believe calls the macro
&lt;code&gt;define-record-type*&lt;/code&gt;.  So I imagine that it is hard for guile to pinpoint,
where the error is.&lt;/p&gt;&lt;p&gt;Anyway, I am really liking coding in GNU Guile.  It is super fun and awesome.  I
just recently discovered &lt;code&gt;match-lambda&lt;/code&gt;, and it's a fantastic GNU Guile macro to
deal with pass around records.&lt;/p&gt;</content></entry></feed>