unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Setting variables, argumunts in defun
@ 2021-02-13 16:14 wael-zwaiter
  2021-02-13 16:33 ` Christopher Dimech
  2021-02-13 19:15 ` Jean Louis
  0 siblings, 2 replies; 11+ messages in thread
From: wael-zwaiter @ 2021-02-13 16:14 UTC (permalink / raw)
  To: Help Gnu Emacs

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) )






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

* Re: Setting variables, argumunts in defun
  2021-02-13 16:14 Setting variables, argumunts in defun wael-zwaiter
@ 2021-02-13 16:33 ` Christopher Dimech
  2021-02-13 16:36   ` wael-zwaiter
  2021-02-13 16:42   ` Philip Kaludercic
  2021-02-13 19:15 ` Jean Louis
  1 sibling, 2 replies; 11+ messages in thread
From: Christopher Dimech @ 2021-02-13 16:33 UTC (permalink / raw)
  To: wael-zwaiter; +Cc: Help Gnu Emacs

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

(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) )
>
>
>
>
>



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

* Re: Setting variables, argumunts in defun
  2021-02-13 16:33 ` Christopher Dimech
@ 2021-02-13 16:36   ` wael-zwaiter
  2021-02-13 16:42   ` Philip Kaludercic
  1 sibling, 0 replies; 11+ messages in thread
From: wael-zwaiter @ 2021-02-13 16:36 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: Help Gnu Emacs

Did not know about pcase.  Could solve my problem with using
strings.

> Sent: Sunday, February 14, 2021 at 4:33 AM
> From: "Christopher Dimech" <dimech@gmx.com>
> To: wael-zwaiter@gmx.com
> Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Setting variables, argumunts in defun
>
> I am trying to use pcase on a string, but do need some direction
> on how to use it.
>
> (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) )
> >
> >
> >
> >
> >
>



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

* Re: Setting variables, argumunts in defun
  2021-02-13 16:33 ` Christopher Dimech
  2021-02-13 16:36   ` wael-zwaiter
@ 2021-02-13 16:42   ` Philip Kaludercic
  2021-02-13 16:52     ` wael-zwaiter
  1 sibling, 1 reply; 11+ messages in thread
From: Philip Kaludercic @ 2021-02-13 16:42 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: Help Gnu Emacs, wael-zwaiter

[-- Attachment #1: Type: text/plain, Size: 1996 bytes --]

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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]

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

* Re: Setting variables, argumunts in defun
  2021-02-13 16:42   ` Philip Kaludercic
@ 2021-02-13 16:52     ` wael-zwaiter
  2021-02-13 16:57       ` tomas
  2021-02-13 17:08       ` Philip Kaludercic
  0 siblings, 2 replies; 11+ messages in thread
From: wael-zwaiter @ 2021-02-13 16:52 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Help Gnu Emacs

Is the following valid?

(setq-local devi 0.18
            scal 1.0)

> Sent: Sunday, February 14, 2021 at 4:42 AM
> From: "Philip Kaludercic" <philipk@posteo.net>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: wael-zwaiter@gmx.com, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Setting variables, argumunts in defun
>
> 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.
>



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

* Re: Setting variables, argumunts in defun
  2021-02-13 16:52     ` wael-zwaiter
@ 2021-02-13 16:57       ` tomas
  2021-02-13 17:23         ` wael-zwaiter
  2021-02-13 17:08       ` Philip Kaludercic
  1 sibling, 1 reply; 11+ messages in thread
From: tomas @ 2021-02-13 16:57 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 882 bytes --]

On Sat, Feb 13, 2021 at 05:52:58PM +0100, wael-zwaiter@gmx.com wrote:
> Is the following valid?
> 
> (setq-local devi 0.18
>             scal 1.0)

Just ask Emacs: C-h f setq-local says:

    ----------------------------------------------------------------
    setq-local is a Lisp macro in ‘subr.el’.
    
    (setq-local [VARIABLE VALUE]...)
    
      Probably introduced at or before Emacs version 24.
    
    Make variables in PAIRS buffer-local and assign them the
    corresponding values.
    
    PAIRS is a list of variable/value pairs.  For each variable,
    make it buffer-local and assign it the corresponding value.
    [rest elided]
    ----------------------------------------------------------------

So I'd say yes, it is valid. Whether it does what you want it to
do I can't say, because you didn't tell us that :-)

Cheers
 - t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: Setting variables, argumunts in defun
  2021-02-13 16:52     ` wael-zwaiter
  2021-02-13 16:57       ` tomas
@ 2021-02-13 17:08       ` Philip Kaludercic
  2021-02-13 17:09         ` Philip Kaludercic
  1 sibling, 1 reply; 11+ messages in thread
From: Philip Kaludercic @ 2021-02-13 17:08 UTC (permalink / raw)
  To: wael-zwaiter; +Cc: Help Gnu Emacs

[-- Attachment #1: Type: text/plain, Size: 2765 bytes --]

wael-zwaiter@gmx.com writes:

> Is the following valid?
>
> (setq-local devi 0.18
>             scal 1.0)

No, because setq-local only accepts one two arguments (variable and
value). Try C-h o setq-local, and you'll see it's documentation.

>> Sent: Sunday, February 14, 2021 at 4:42 AM
>> From: "Philip Kaludercic" <philipk@posteo.net>
>> To: "Christopher Dimech" <dimech@gmx.com>
>> Cc: wael-zwaiter@gmx.com, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
>> Subject: Re: Setting variables, argumunts in defun
>>
>> 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.
>>

-- 
	Philip K.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]

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

* Re: Setting variables, argumunts in defun
  2021-02-13 17:08       ` Philip Kaludercic
@ 2021-02-13 17:09         ` Philip Kaludercic
  0 siblings, 0 replies; 11+ messages in thread
From: Philip Kaludercic @ 2021-02-13 17:09 UTC (permalink / raw)
  To: wael-zwaiter; +Cc: Help Gnu Emacs

[-- Attachment #1: Type: text/plain, Size: 303 bytes --]

Philip Kaludercic <philipk@posteo.net> writes:

> No, because setq-local only accepts one two arguments (variable and
> value). Try C-h o setq-local, and you'll see it's documentation.

Disregard this, I didn't notice that setq-local was updated to set more
than one variable.

-- 
	Philip K.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]

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

* Re: Setting variables, argumunts in defun
  2021-02-13 16:57       ` tomas
@ 2021-02-13 17:23         ` wael-zwaiter
  2021-02-13 22:59           ` Michael Heerdegen
  0 siblings, 1 reply; 11+ messages in thread
From: wael-zwaiter @ 2021-02-13 17:23 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs

There seems to be some problem with the following test
Am getting "Wrong number of arguments: (2 . 2), 4"


(defun test (objv)
  "Set some local variables."

  (pcase objv
    ( "enable"
      (setq-local devi '(0.18 -0.18)
                  scal  0.2))

    ( "disable"
      (setq-local devi '(0.0 0.0)
                  scal  1.0)) ) )

(defun myenable ()
  "Enable."
  (interactive)
  (test "enable") )



> Sent: Sunday, February 14, 2021 at 4:57 AM
> From: tomas@tuxteam.de
> To: help-gnu-emacs@gnu.org
> Subject: Re: Setting variables, argumunts in defun
>
> On Sat, Feb 13, 2021 at 05:52:58PM +0100, wael-zwaiter@gmx.com wrote:
> > Is the following valid?
> > 
> > (setq-local devi 0.18
> >             scal 1.0)
> 
> Just ask Emacs: C-h f setq-local says:
> 
>     ----------------------------------------------------------------
>     setq-local is a Lisp macro in ‘subr.el’.
>     
>     (setq-local [VARIABLE VALUE]...)
>     
>       Probably introduced at or before Emacs version 24.
>     
>     Make variables in PAIRS buffer-local and assign them the
>     corresponding values.
>     
>     PAIRS is a list of variable/value pairs.  For each variable,
>     make it buffer-local and assign it the corresponding value.
>     [rest elided]
>     ----------------------------------------------------------------
> 
> So I'd say yes, it is valid. Whether it does what you want it to
> do I can't say, because you didn't tell us that :-)
> 
> Cheers
>  - t
>



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

* Re: Setting variables, argumunts in defun
  2021-02-13 16:14 Setting variables, argumunts in defun wael-zwaiter
  2021-02-13 16:33 ` Christopher Dimech
@ 2021-02-13 19:15 ` Jean Louis
  1 sibling, 0 replies; 11+ messages in thread
From: Jean Louis @ 2021-02-13 19:15 UTC (permalink / raw)
  To: wael-zwaiter; +Cc: Help Gnu Emacs

* wael-zwaiter@gmx.com <wael-zwaiter@gmx.com> [2021-02-13 19:19]:
> 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) )

I am trying to understand. How are you selecting either one or the
other?

What is devi? What is scal? Is that meaning something special?

If you mean to make a function to set variable devi or scal, you could
do maybe function like this:

(defun devi-scal (&optional devi-value scal-vale)
  (when devi
    (setq devi devi))
  (when scal
    (setq scal scal)))

But that implies that variables `devi' and `scal' are global and
you wish to set global variable.

Then you could use (devi-scal 0.18 nil) to set only variable
`devi' or (devi-cale nil 0.18) to set only variable `scal'
or (devi-scal 0.18 1.0) to set both of them.

Is that what you mean?

Jean



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

* Re: Setting variables, argumunts in defun
  2021-02-13 17:23         ` wael-zwaiter
@ 2021-02-13 22:59           ` Michael Heerdegen
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Heerdegen @ 2021-02-13 22:59 UTC (permalink / raw)
  To: help-gnu-emacs

wael-zwaiter@gmx.com writes:

> Am getting "Wrong number of arguments: (2 . 2), 4"
>
>       (setq-local devi '(0.18 -0.18)
>                   scal  0.2))

Older Emacsen don't yet support this syntax.  You need at least a 27
major version Emacs or so.  Why don't you ask your Emacs?

Michael.




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

end of thread, other threads:[~2021-02-13 22:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-13 16:14 Setting variables, argumunts in defun wael-zwaiter
2021-02-13 16:33 ` Christopher Dimech
2021-02-13 16:36   ` wael-zwaiter
2021-02-13 16:42   ` Philip Kaludercic
2021-02-13 16:52     ` wael-zwaiter
2021-02-13 16:57       ` tomas
2021-02-13 17:23         ` wael-zwaiter
2021-02-13 22:59           ` Michael Heerdegen
2021-02-13 17:08       ` Philip Kaludercic
2021-02-13 17:09         ` Philip Kaludercic
2021-02-13 19:15 ` Jean Louis

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).