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

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

Re: Setting variables, argumunts in defun


From: Philip Kaludercic
Subject: Re: Setting variables, argumunts in defun
Date: Sat, 13 Feb 2021 17:42:12 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Christopher Dimech <dimech@gmx.com> writes:

> I am trying to use pcase on a string, but do need some direction
> on how to use it.

Pcase is usually used like this

        (pcase objv
          ("enable"
           (setq devi 0.18)
           (setq scal 0.2))
          ("disable"
           (setq devi 0.18)
           (setq scal 1.0)))

the first element it the expression that the execution depends on, and
every possible branch starts with a case. What you are doing looks more
like a cond-expression:

        (cond ((string-equal objv "enable")
               (setq devi 0.18)
               (setq scal 0.2))
              ((string-equal objv "disable")
               (setq devi 0.18)
               (setq scal 1.0)))

That being said, it's probably better to use a symbol ('enable and
'disable) or a boolean value write this. Exploiting the fact that setq
can assign multiple variables at one, you could also write

        (if (eq objv 'enable)
            (setq devi 0.18
                  scal 0.2)
          (setq devi 0.18
                scal 1.0))

though depending on what you are doing, it might be better to avoid
setting global variables in the first place.

> (pcase (string-match "enable" objv)
>       (
>        (setq devi 0.18)
>        (setq scal 0.2) )
>
>     ( (string-match "disable" objv)
>      (setq devi 0.0)
>      (setq scal 1.0) )
>
>     )
>
>
>> Sent: Sunday, February 14, 2021 at 4:14 AM
>> From: wael-zwaiter@gmx.com
>> To: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
>> Subject: Setting variables, argumunts in defun
>>
>> I would like to set up devi and scal by selecting either one or
>> the other.  Wow can I do this in elisp.  Should I pass parameters
>> to the function.  Can one pass a string, then check its contents?
>>
>> (defun deviscal ()
>>
>>   (setq devi 0.18)
>>   (setq scal 0.2)
>>
>>   (setq devi 0.0)
>>   (setq scal 1.0) )
>>
>>
>>
>>
>>
>
>

-- 
        Philip K.

Attachment: signature.asc
Description: PGP signature


reply via email to

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