unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* How can I step through this code?
@ 2022-10-06  3:05 jgart
  2022-10-07 18:45 ` jbranso
  2022-10-10 16:04 ` Ludovic Courtès
  0 siblings, 2 replies; 13+ messages in thread
From: jgart @ 2022-10-06  3:05 UTC (permalink / raw)
  To: Guix Help

Hi

How can I step through this code?

(define-syntax do
  (syntax-rules ()
    ((do ((var init step ...) ...)
         (test expr ...)
         command ...)
     (letrec
       ((loop
         (lambda (var ...)
           (if test
               (begin
                 (if #f #f)
                 expr ...)
               (begin
                 command
                 ...
                 (loop (do "step" var step ...)
                       ...))))))
       (loop init ...)))
    ((do "step" x)
     x)
    ((do "step" x y)
     y)))



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-06  3:05 How can I step through this code? jgart
@ 2022-10-07 18:45 ` jbranso
  2022-10-07 19:22   ` jgart
  2022-10-07 21:52   ` jbranso
  2022-10-10 16:04 ` Ludovic Courtès
  1 sibling, 2 replies; 13+ messages in thread
From: jbranso @ 2022-10-07 18:45 UTC (permalink / raw)
  To: jgart, Guix Help

October 5, 2022 11:06 PM, "jgart" <jgart@dismail.de> wrote:

> Hi
> 
> How can I step through this code?
> 

If you ever find out, then let me know!

I wish guile had a nice debugger like elisp.  :)

> (define-syntax do
> (syntax-rules ()
> ((do ((var init step ...) ...)
> (test expr ...)
> command ...)
> (letrec
> ((loop
> (lambda (var ...)
> (if test
> (begin
> (if #f #f)
> expr ...)
> (begin
> command
> ...
> (loop (do "step" var step ...)
> ...))))))
> (loop init ...)))
> ((do "step" x)
> x)
> ((do "step" x y)
> y)))


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-07 18:45 ` jbranso
@ 2022-10-07 19:22   ` jgart
  2022-10-07 21:52   ` jbranso
  1 sibling, 0 replies; 13+ messages in thread
From: jgart @ 2022-10-07 19:22 UTC (permalink / raw)
  To: jbranso; +Cc: Guix Help

On Fri, 07 Oct 2022 18:45:36 +0000 jbranso@dismail.de wrote:
> I wish guile had a nice debugger like elisp.  :)

I wish guile had a nice debugger like racket or common lisp.  :)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-07 18:45 ` jbranso
  2022-10-07 19:22   ` jgart
@ 2022-10-07 21:52   ` jbranso
  2022-10-08  1:25     ` jgart
  2022-10-08 15:03     ` jbranso
  1 sibling, 2 replies; 13+ messages in thread
From: jbranso @ 2022-10-07 21:52 UTC (permalink / raw)
  To: jgart; +Cc: Guix Help

October 7, 2022 3:22 PM, "jgart" <jgart@dismail.de> wrote:

> On Fri, 07 Oct 2022 18:45:36 +0000 jbranso@dismail.de wrote:
> 
>> I wish guile had a nice debugger like elisp. :)
> 
> I wish guile had a nice debugger like racket or common lisp. :)

I haven't actually tried those debuggers...


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-07 21:52   ` jbranso
@ 2022-10-08  1:25     ` jgart
  2022-10-08 15:03     ` jbranso
  1 sibling, 0 replies; 13+ messages in thread
From: jgart @ 2022-10-08  1:25 UTC (permalink / raw)
  To: jbranso; +Cc: Guix Help

On Fri, 07 Oct 2022 21:52:40 +0000 jbranso@dismail.de wrote:
> October 7, 2022 3:22 PM, "jgart" <jgart@dismail.de> wrote:
> 
> > On Fri, 07 Oct 2022 18:45:36 +0000 jbranso@dismail.de wrote:
> > 
> >> I wish guile had a nice debugger like elisp. :)
> > 
> > I wish guile had a nice debugger like racket or common lisp. :)
> 
> I haven't actually tried those debuggers...

Just paste some guile code into drracket and press debug to start stepping through the Guile code.

This guile code should work:

(define (list-index l k)
  (let loop ((n 0)
             (l l))
    (and (not (null? l))
         (if (eq? (car l) k)
             n
             (loop (+ n 1) (cdr l))))))

(list-index '(1 2 3 4 5 6 7 8 9) 2)

Just make sure you put the following at the top of the file:

#lang racket

Of course not all guile code would work because it's Guile and Racket
but some subsets of Guile can be used from the drracket debugger.

;()


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-07 21:52   ` jbranso
  2022-10-08  1:25     ` jgart
@ 2022-10-08 15:03     ` jbranso
  2022-10-08 17:23       ` jgart
  2022-10-09  0:14       ` jbranso
  1 sibling, 2 replies; 13+ messages in thread
From: jbranso @ 2022-10-08 15:03 UTC (permalink / raw)
  To: jgart; +Cc: Guix Help

October 7, 2022 9:25 PM, "jgart" <jgart@dismail.de> wrote:

> On Fri, 07 Oct 2022 21:52:40 +0000 jbranso@dismail.de wrote:
> 
>> October 7, 2022 3:22 PM, "jgart" <jgart@dismail.de> wrote:
>> 
>> On Fri, 07 Oct 2022 18:45:36 +0000 jbranso@dismail.de wrote:
>> 
>> I wish guile had a nice debugger like elisp. :)
>> 
>> I wish guile had a nice debugger like racket or common lisp. :)
>> 
>> I haven't actually tried those debuggers...
> 
> Just paste some guile code into drracket and press debug to start stepping through the Guile code.

That's smart! 

> 
> This guile code should work:
> 
> (define (list-index l k)
> (let loop ((n 0)
> (l l))
> (and (not (null? l))
> (if (eq? (car l) k)
> n
> (loop (+ n 1) (cdr l))))))
> 
> (list-index '(1 2 3 4 5 6 7 8 9) 2)
> 
> Just make sure you put the following at the top of the file:
> 
> #lang racket
> 
> Of course not all guile code would work because it's Guile and Racket
> but some subsets of Guile can be used from the drracket debugger.
> 
> ;()


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-08 15:03     ` jbranso
@ 2022-10-08 17:23       ` jgart
  2022-10-09  0:14       ` jbranso
  1 sibling, 0 replies; 13+ messages in thread
From: jgart @ 2022-10-08 17:23 UTC (permalink / raw)
  To: jbranso; +Cc: Guix Help

On Sat, 08 Oct 2022 15:03:54 +0000 jbranso@dismail.de wrote:
> That's smart! 

Did you try it? I've been trying to understand how some Guile code works
by just throwing it in the Racket debugger. It doesn't always work but
when it does it's like driving a fancy cadillac through the stack.

It's too bad that Guile's debugger sucks compared to Racket's debugger. Maybe
someday someone will implement something amazing for that.

RE The Common Lisp debugger: It's really great but it might be a rabbit hole.

I recommend using sly or slime with sbcl if you want to go down that.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-08 15:03     ` jbranso
  2022-10-08 17:23       ` jgart
@ 2022-10-09  0:14       ` jbranso
  2022-10-09 16:30         ` jgart
  2022-10-10 19:49         ` jbranso
  1 sibling, 2 replies; 13+ messages in thread
From: jbranso @ 2022-10-09  0:14 UTC (permalink / raw)
  To: jgart; +Cc: Guix Help

October 8, 2022 1:23 PM, "jgart" <jgart@dismail.de> wrote:

> On Sat, 08 Oct 2022 15:03:54 +0000 jbranso@dismail.de wrote:
> 
>> That's smart!
> 
> Did you try it? I've been trying to understand how some Guile code works
> by just throwing it in the Racket debugger. It doesn't always work but
> when it does it's like driving a fancy cadillac through the stack.

hahaha!  I have not tried it.   I definitely should.

I ran into this common problem yesterday.  I am of course simplifying:

(string-append "hello"
               (if some-var
                   " world\n"))

error: expecting type string
(string-append "hello" #unspecified)


It took me an embarrassing amount of time to track down where the 
#unspecified was coming from.

I feel like the error message was a little bit cryptic.  It said that 
one particular function cause the error...It just took me a while to track
it down.  A debugger stepping through the code would have been awesome!
 
> It's too bad that Guile's debugger sucks compared to Racket's debugger. Maybe
> someday someone will implement something amazing for that.
> 
> RE The Common Lisp debugger: It's really great but it might be a rabbit hole.
> 
> I recommend using sly or slime with sbcl if you want to go down that.

Right now I am super in love with Guix.  My main squeeze is working
on our existing opensmtpd-service and letting users configure it with
proper scheme records.  I don't know if I want to play with common lisp.

Thanks,

Joshua


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-09  0:14       ` jbranso
@ 2022-10-09 16:30         ` jgart
  2022-10-10 19:49         ` jbranso
  1 sibling, 0 replies; 13+ messages in thread
From: jgart @ 2022-10-09 16:30 UTC (permalink / raw)
  To: jbranso; +Cc: Guix Help

On Sun, 09 Oct 2022 00:14:23 +0000 jbranso@dismail.de wrote:
> A debugger stepping through the code would have been awesome!

Yup it would have! You're right!

> Right now I am super in love with Guix.  

Me too, it's more like a passionate love hate relationship for me tbh. I
need couples GNUtherapy.

> My main squeeze is working
> on our existing opensmtpd-service and letting users configure it with
> proper scheme records.  I don't know if I want to play with common lisp.

Ya, it's a rabbit hole although I recommend atleast once, taking a stack
stroll in the caddy just so you know what's up ;()


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-06  3:05 How can I step through this code? jgart
  2022-10-07 18:45 ` jbranso
@ 2022-10-10 16:04 ` Ludovic Courtès
  2022-10-10 17:00   ` jgart
  1 sibling, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2022-10-10 16:04 UTC (permalink / raw)
  To: jgart; +Cc: Guix Help

Hi,

jgart <jgart@dismail.de> skribis:

> How can I step through this code?
>
> (define-syntax do
>   (syntax-rules ()
>     ((do ((var init step ...) ...)
>          (test expr ...)
>          command ...)
>      (letrec
>        ((loop
>          (lambda (var ...)
>            (if test
>                (begin
>                  (if #f #f)
>                  expr ...)
>                (begin
>                  command
>                  ...
>                  (loop (do "step" var step ...)
>                        ...))))))
>        (loop init ...)))
>     ((do "step" x)
>      x)
>     ((do "step" x y)
>      y)))

You can’t: this is a macro and Guile doesn’t have a “macro stepper”
(Racket does).

What you can do though, is define the macro and expand it on examples of
your choosing to see how it behaves:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,expand (do ((x 0 (+ 1 x))) ((>= x 10)) (pk x))
$7 = (let loop ((x 0))
  (if (>= x 10)
    (if #f #f)
    (begin (pk x) (loop (+ 1 x)))))
scheme@(guile-user)> ,optimize (do ((x 0 (+ 1 x))) ((>= x 10)) (pk x))
$8 = (begin
  (pk 0)
  (pk 1)
  (pk 2)
  (pk 3)
  (pk 4)
  (pk 5)
  (pk 6)
  (pk 7)
  (pk 8)
  (pk 9)
  (if #f #f))
--8<---------------cut here---------------end--------------->8---

(Personally I’ve never used ‘do’ and I don’t feel like starting today. :-))

Ludo’.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-10 16:04 ` Ludovic Courtès
@ 2022-10-10 17:00   ` jgart
  0 siblings, 0 replies; 13+ messages in thread
From: jgart @ 2022-10-10 17:00 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: Guix Help

On Mon, 10 Oct 2022 18:04:57 +0200 Ludovic Courtès <ludo@gnu.org> wrote:
> What you can do though, 

Thanks Ludo! Much appreciated!! I hadn't used ,optimize metacommand yet. I've used
pk in Guile and Racket but not regularly tbh. Maybe I should start.

Ludo, how would you step through this code?

(define (list-index l k)
  (let loop ((n 0)
             (l l))
    (and (not (null? l))
         (if (eq? (car l) k)
             n
             (loop (+ n 1) (cdr l))))))

(list-index '(1 2 3 4 5 6 7 8 9) 2)

What is your approach with Guile?

all best,

jgart



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-09  0:14       ` jbranso
  2022-10-09 16:30         ` jgart
@ 2022-10-10 19:49         ` jbranso
  2022-10-10 22:40           ` jgart
  1 sibling, 1 reply; 13+ messages in thread
From: jbranso @ 2022-10-10 19:49 UTC (permalink / raw)
  To: jgart; +Cc: Guix Help

October 9, 2022 12:30 PM, "jgart" <jgart@dismail.de> wrote:

> On Sun, 09 Oct 2022 00:14:23 +0000 jbranso@dismail.de wrote:
> 
>> A debugger stepping through the code would have been awesome!
> 
> Yup it would have! You're right!
> 
>> Right now I am super in love with Guix.
> 
> Me too, it's more like a passionate love hate relationship for me tbh. I
> need couples GNUtherapy.
> 
>> My main squeeze is working
>> on our existing opensmtpd-service and letting users configure it with
>> proper scheme records. I don't know if I want to play with common lisp.
> 
> Ya, it's a rabbit hole although I recommend atleast once, taking a stack
> stroll in the caddy just so you know what's up ;()

ahaha.  I guess there is an OS written in common lisp...


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How can I step through this code?
  2022-10-10 19:49         ` jbranso
@ 2022-10-10 22:40           ` jgart
  0 siblings, 0 replies; 13+ messages in thread
From: jgart @ 2022-10-10 22:40 UTC (permalink / raw)
  To: jbranso; +Cc: Guix Help

On Mon, 10 Oct 2022 19:49:23 +0000 jbranso@dismail.de wrote:
> October 9, 2022 12:30 PM, "jgart" <jgart@dismail.de> wrote:
> 
> > On Sun, 09 Oct 2022 00:14:23 +0000 jbranso@dismail.de wrote:
> > 
> >> A debugger stepping through the code would have been awesome!
> > 
> > Yup it would have! You're right!
> > 
> >> Right now I am super in love with Guix.
> > 
> > Me too, it's more like a passionate love hate relationship for me tbh. I
> > need couples GNUtherapy.
> > 
> >> My main squeeze is working
> >> on our existing opensmtpd-service and letting users configure it with
> >> proper scheme records. I don't know if I want to play with common lisp.
> > 
> > Ya, it's a rabbit hole although I recommend atleast once, taking a stack
> > stroll in the caddy just so you know what's up ;()
> 
> ahaha.  I guess there is an OS written in common lisp...

ya anything rust can do CL could do better jk (not jk)


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-10-10 22:41 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-06  3:05 How can I step through this code? jgart
2022-10-07 18:45 ` jbranso
2022-10-07 19:22   ` jgart
2022-10-07 21:52   ` jbranso
2022-10-08  1:25     ` jgart
2022-10-08 15:03     ` jbranso
2022-10-08 17:23       ` jgart
2022-10-09  0:14       ` jbranso
2022-10-09 16:30         ` jgart
2022-10-10 19:49         ` jbranso
2022-10-10 22:40           ` jgart
2022-10-10 16:04 ` Ludovic Courtès
2022-10-10 17:00   ` jgart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).