help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Making ielm behave like a shell (getting to previous commands using


From: Jean Louis
Subject: Re: Making ielm behave like a shell (getting to previous commands using the up-arrow key)
Date: Fri, 18 Dec 2020 21:36:42 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

* Drew Adams <drew.adams@oracle.com> [2020-12-18 20:14]:
> > First step:
> > 
> > (let* ((mailing-hash (rcd-db-table-id-hash "mailinglistoptions" option 
> > *cf*))
> >        (mid (gethash 'mailinglistoptions_accounts mailing-hash))
> >        (mid-hash (rcd-db-table-id-hash "accounts" mid *cf*))
> >        (accounts-hash (rcd-db-table-id-hash "accounts" mid *cf*))
> >        (email-list (rcd-email-list mid))))
> > 
> > Second step:
> > 
> > (let* ((setq mailing-hash (rcd-db-table-id-hash "mailinglistoptions" option 
> > *cf*))
> >        (mid (gethash 'mailinglistoptions_accounts mailing-hash))
> >        (mid-hash (rcd-db-table-id-hash "accounts" mid *cf*))
> >        (accounts-hash (rcd-db-table-id-hash "accounts" mid *cf*))
> >        (email-list (rcd-email-list mid))))
> 
> Nope.  That raises an error telling you
>  "`let' bindings can have only one value-form".

It was description of my way of debugging programs. I learned it
online from Common Lisp. As I live isolated and not together in one
room with any programmer neither I know ANY in this city and country
where I am located I might catch something that is not common and
continue with it for years just as it would be common.

You cannot evaluate those forms alone or whole, as that is just
description of step by step debugging. Programs do not run with `setq'
there, it is inserted temporary to assign some variables step by step
until I find what is wrong. That way of debugging worked well for
me. But now I explore much easier edebug-defun, but I do not know how
to stop edebugging.

> FYI, that `let' has an empty body - it has only bindings.

Because it was demonstration of step by step rather rudimentary
debugging method. The whole function works just fine, I know that as
3917 emails were sent by using it.

> More importantly, this "binding" is erroneous:
> 
> (setq mailing-hash (rcd-db-table-id-hash ...))

That was demonstration. I insert `setq' to bind temporarily
`mailing-hash' during my debugging process. I wish I would know before
about edebug-defun, but I did not. After inserting setq, I would
delete it. My habit is so strong that I may continue doing that for
months until I get into edebug-defun

> CAN you use a `setq' or other procedural code inside
> a let-binding?  Sure, if you want to.  Just provide a
> variable to bind to it.
> 
> (let* ((fred      42)
>        (_IGNORED  (setq fred  'nope-24))
>        (_NADA     (message "FRED: %S" fred)))
>   ;; Empty body, if you like
>   )
> 
> (Nothing special about the variable names.  But an
> underscore prefix is sometimes used conventionally
> to tell human readers that the thingy isn't really
> used or isn't used in some particular way.  Here,
> I use it to tell myself that the variable is used
> only to be able to evaluate some sexp for its side
> effect.  And I use uppercase just to make this
> weirdness more obvious to myself.)

I have seen it works with _ alone

> You can also bind the same variable multiple times,
> if you like:
> 
> (let* ((fred   42)
>        (alice  (foo fred))
>        (fred   (if (> fred 0) 24 'derf))
>        (fred   '(nah dont-do-that at-all)))
>  (message "FRED: %S" fred))

Of course, I do that.

> IOW:
> 
> You can put any kind of procedural code in a `let' body
> or a `let' binding.  If in a binding, it needs to be as
> a sexp to evaluate and bind to some variable.

Only it does not look nice any more. So often I will jump out of first
let and continue with second let.

> You can use multiple, sequential bindings for the same
> variable, if you use `let*'.

Which * joker symbol I often forget. That is my major error in Elisp.

> > Third step:
> > 
> > (let* ((mailing-hash (rcd-db-table-id-hash "mailinglistoptions" option 
> > *cf*))
> >        (setq mid (gethash 'mailinglistoptions_accounts mailing-hash))
>          ^^^^^^^^^^^^^^^^^^^...
> Same problem as above.

That is some misunderstanding. I hope you got it now.

How do you debug? You use edebug-defun?

> > How would you do message calls there?
> 
> See above.  Put any procedural code you want to use
> in the bindings part into a binding: provide a var
> that you use or don't use, binding it to the code
> you want to evaluate for its side effects.
> 
> Is this kind of thing great style?  Maybe not.  But
> you can do it.
> 
> Being able to add `message' calls wherever you want
> can be helpful.

That I did not understand. Why now show example of message call? What
is it? Do you mean (message something)?

> Another thing you can add, as an alternative to
> `message' calls, are calls to `debug'.  Those are
> essentially breakpoints.  They let you know which
> branch of code gets executed, opening the debugger
> when encountered.
> 
> (let* ((fred   42)
>        (_ZIP   (setq fred  'nope-24))
>        (_NADA  (when (toto) (debug nil fred))))
>   (unless (titi) (debug))
>   ;;...
>   )
> 
> `C-h f debug'...

Useful function. Is there anyway to get out of debug and continue the
function? c does not do what I think it should do. I would like to
exit out of debug and continue with the function. Any way?





reply via email to

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