guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guile debugger workgroup?


From: Maxim Cournoyer
Subject: Re: Guile debugger workgroup?
Date: Sun, 27 Nov 2022 19:27:04 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

Hi Simon,

zimoun <zimon.toutoune@gmail.com> writes:

[...]

> Racket is an example of functional programming and live coding.  Haskell
> is another; it is functional programming and if I might, I would
> recommend to give a look at the interactive GHCi debugger [1].
>
> Back to the initial example [2].  Racket is able to set breakpoints at
> various places, as shown in the short demo [3].  Well, I am not able to
> do that with Guile.
>
> $ cat -n my-target.scm
>      1        ;#lang racket
>      2        
>      3        (define (mutate-once x)
>      4          (let ((once "once")
>      5                (dash "-"))
>      6            (string-append x dash once)))
>      7        
>      8        (define (mutate-twice x)
>      9          (let* ((dash "-")
>     10                 (twice "twice")
>     11                 (stuff (string-append twice dash)))
>     12          (string-append "twice-" x)))
>     13        
>     14        (define (do-something-with x)
>     15          (string-length x))
>     16        
>     17        (define (example x)
>     18          (let* ((my-target "something")
>     19                 (my-target (mutate-once my-target))
>     20                 (my-target (mutate-twice my-target)))
>     21            (do-something-with my-target)))
>
>
> then,
>
> $ guix repl
> GNU Guile 3.0.8
> Copyright (C) 1995-2021 Free Software Foundation, Inc.
>
> Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
> This program is free software, and you are welcome to redistribute it
> under certain conditions; type `,show c' for details.
>
> Enter `,help' for help.
> scheme@(guix-user)> (load "my-target.scm")
> scheme@(guix-user)> ,break-at-source "my-target.scm" 17
> While executing meta-command:
> No procedures found at ~a:~a. "my-target.scm" 17
> scheme@(guix-user)> ,break-at-source "/home/simon/tmp/my-target.scm" 17
> While executing meta-command:
> No procedures found at ~a:~a. "/home/simon/tmp/my-target.scm" 17
> scheme@(guix-user)> (example #t)
> $1 = 20
> scheme@(guix-user)> ,break example
> Trap 2: Breakpoint at #<procedure example (a)>.
> scheme@(guix-user)> (example #t)
> $2 = 20
> scheme@(guix-user)>
>
>
> How can I enter in the debugger?  Do I only enter on error?  Well, I end
> to put ’pk’ here and there to inspect the code.  Poor experience. :-)
>
> Just to compare with Haskell (functional style, where it is hard nor
> impossible to put equivalent of ’pk’ here or there :-)) – the code is
> the equivalent as above.
>
>      1        mutate_once x = x ++ dash ++ once
>      2          where
>      3            once = "once"
>      4            dash = "-"
>      5        
>      6        mutate_twice x = stuff ++ x
>      7          where
>      8            dash = "-"
>      9            twice = "once"
>     10            stuff = twice ++ dash
>     11        
>     12        do_something_with x = length x
>     13        
>     14        example x = do_something_with my_target
>     15          where
>     16            my_target = mutate_twice my_target
>     17              where
>     18                my_target = mutate_once my_target
>     19                  where
>     20                    my_target = "something"
>
>
> then,
>
> $ guix shell ghc gcc-toolchain -- ghci
> GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
> Prelude> :load my-target.hs
> [1 of 1] Compiling Main             ( my-target.hs, interpreted )
> Ok, one module loaded.
> *Main> :break 14
> Breakpoint 0 activated at my-target.hs:14:13-39
> *Main> example True
> Stopped in Main.example, my-target.hs:14:13-39
> _result :: Int = _
> my_target :: [Char] = _
> [my-target.hs:14:13-39] *Main> :list
> 13  
> 14  example x = do_something_with my_target
>                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 15    where
> [my-target.hs:14:13-39] *Main> :break 18
> Breakpoint 1 activated at my-target.hs:18:21-41
> [my-target.hs:14:13-39] *Main> :continue
> Stopped in Main.example.my_target.my_target, my-target.hs:18:21-41
> _result :: [Char] = _
> my_target :: [Char] = _
> [my-target.hs:18:21-41] *Main> :list
> 17        where
> 18          my_target = mutate_once my_target
>                         ^^^^^^^^^^^^^^^^^^^^^
> 19            where
> [my-target.hs:18:21-41] *Main> my_target
> "something"
> [my-target.hs:18:21-41] *Main>
>
>
> Well, again maybe I miss how to use the Guile debugger.  From my small
> experience, I have hard time to debug and inspect Guile code.

I think your above example summarizes well what appears to be wrong with
the Guile debugging experience; at least I personally strongly relate.

We should turn this kind of scenario into unit tests for Guile; the
output of the workgroup could then be to make these pass!  There are
also paper cuts such as the malformed error message "No procedures found
at ~a:~a. "my-target.scm" 17".

When searching for how the debugger work in the Guile Reference info
manual, I also don't find anything useful: only the gut of the debugging
API of the Guile VM appears to be documented ("Debugging
Infrastructure"), so documentation is another place that could be
improved, with some examples and pro tips for real life, practical
debugging with Guile.

-- 
Thanks,
Maxim



reply via email to

[Prev in Thread] Current Thread [Next in Thread]