all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Defining an array in a let clause.
@ 2022-12-05 11:40 Heime
  2022-12-05 12:54 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Heime @ 2022-12-05 11:40 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor


How can I set up an array of five elements in a let clause.

  (let ( (ss (nth 0 (decode-time)))    ; seconds
         (mm (nth 1 (decode-time)))    ; minutes
         (hh (nth 2 (decode-time)))    ; hours
         (us (nth 2 (current-time)))   ; microsecond
         (ps (nth 3 (current-time)))   ; picosecond
         (lc (make-array '(5))) )







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

* Re: Defining an array in a let clause.
  2022-12-05 11:40 Defining an array in a let clause Heime
@ 2022-12-05 12:54 ` Eli Zaretskii
  2022-12-05 13:56   ` Heime
  2022-12-05 19:42 ` Jean Louis
  2022-12-05 21:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2022-12-05 12:54 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Mon, 05 Dec 2022 11:40:44 +0000
> From: Heime <heimeborgia@protonmail.com>
> 
> 
> How can I set up an array of five elements in a let clause.
> 
>   (let ( (ss (nth 0 (decode-time)))    ; seconds
>          (mm (nth 1 (decode-time)))    ; minutes
>          (hh (nth 2 (decode-time)))    ; hours
>          (us (nth 2 (current-time)))   ; microsecond
>          (ps (nth 3 (current-time)))   ; picosecond
>          (lc (make-array '(5))) )

There are no arrays in Emacs.  Do you mean vector? if so use the function
'vector' to construct a vector.  If, OTOH, you want a list, use the function
'list' instead.



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

* Re: Defining an array in a let clause.
  2022-12-05 12:54 ` Eli Zaretskii
@ 2022-12-05 13:56   ` Heime
  2022-12-05 14:42     ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Heime @ 2022-12-05 13:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

------- Original Message -------
On Monday, December 5th, 2022 at 12:54 PM, Eli Zaretskii <eliz@gnu.org> wrote:


> > Date: Mon, 05 Dec 2022 11:40:44 +0000
> > From: Heime heimeborgia@protonmail.com
> > 
> > How can I set up an array of five elements in a let clause.
> > 
> > (let ( (ss (nth 0 (decode-time))) ; seconds
> > (mm (nth 1 (decode-time))) ; minutes
> > (hh (nth 2 (decode-time))) ; hours
> > (us (nth 2 (current-time))) ; microsecond
> > (ps (nth 3 (current-time))) ; picosecond
> > (lc (make-array '(5))) )
> 
> 
> There are no arrays in Emacs. Do you mean vector? if so use the function
> 'vector' to construct a vector. If, OTOH, you want a list, use the function
> 'list' instead.

Correct, a vector with five elements.



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

* Re: Defining an array in a let clause.
  2022-12-05 13:56   ` Heime
@ 2022-12-05 14:42     ` Eli Zaretskii
  2022-12-05 18:12       ` Eduardo Ochs
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2022-12-05 14:42 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Mon, 05 Dec 2022 13:56:53 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: help-gnu-emacs@gnu.org
> 
> ------- Original Message -------
> On Monday, December 5th, 2022 at 12:54 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
> 
> > > Date: Mon, 05 Dec 2022 11:40:44 +0000
> > > From: Heime heimeborgia@protonmail.com
> > > 
> > > How can I set up an array of five elements in a let clause.
> > > 
> > > (let ( (ss (nth 0 (decode-time))) ; seconds
> > > (mm (nth 1 (decode-time))) ; minutes
> > > (hh (nth 2 (decode-time))) ; hours
> > > (us (nth 2 (current-time))) ; microsecond
> > > (ps (nth 3 (current-time))) ; picosecond
> > > (lc (make-array '(5))) )
> > 
> > 
> > There are no arrays in Emacs. Do you mean vector? if so use the function
> > 'vector' to construct a vector. If, OTOH, you want a list, use the function
> > 'list' instead.
> 
> Correct, a vector with five elements.

Then the function 'vector' is what you need to use here.



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

* Re: Defining an array in a let clause.
  2022-12-05 14:42     ` Eli Zaretskii
@ 2022-12-05 18:12       ` Eduardo Ochs
  0 siblings, 0 replies; 8+ messages in thread
From: Eduardo Ochs @ 2022-12-05 18:12 UTC (permalink / raw)
  To: Heime; +Cc: help-gnu-emacs

On Mon, 5 Dec 2022 at 11:44, Eli Zaretskii <eliz@gnu.org> wrote:
>
> > Date: Mon, 05 Dec 2022 13:56:53 +0000
> > From: Heime <heimeborgia@protonmail.com>
> > Cc: help-gnu-emacs@gnu.org
> >
> > ------- Original Message -------
> > On Monday, December 5th, 2022 at 12:54 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> >
> >
> > > > Date: Mon, 05 Dec 2022 11:40:44 +0000
> > > > From: Heime heimeborgia@protonmail.com
> > > >
> > > > How can I set up an array of five elements in a let clause.
> > > >
> > > > (let ( (ss (nth 0 (decode-time))) ; seconds
> > > > (mm (nth 1 (decode-time))) ; minutes
> > > > (hh (nth 2 (decode-time))) ; hours
> > > > (us (nth 2 (current-time))) ; microsecond
> > > > (ps (nth 3 (current-time))) ; picosecond
> > > > (lc (make-array '(5))) )
> > >
> > >
> > > There are no arrays in Emacs. Do you mean vector? if so use the function
> > > 'vector' to construct a vector. If, OTOH, you want a list, use the function
> > > 'list' instead.
> >
> > Correct, a vector with five elements.
>
> Then the function 'vector' is what you need to use here.

Try this:

  (cl-destructuring-bind (ss mm hh &rest rest) (decode-time)
    (cl-destructuring-bind (_ _ us ps &rest rest) (current-time)
      (vector ss mm hh us ps)))

I don't know cl-lib well... I guess that there are better ways to
do that, and I hope that other people would come up and show
what are these better ways... =)
  Cheers,
    Edrx
    http://angg.twu.net/eepitch.html



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

* Re: Defining an array in a let clause.
  2022-12-05 11:40 Defining an array in a let clause Heime
  2022-12-05 12:54 ` Eli Zaretskii
@ 2022-12-05 19:42 ` Jean Louis
  2022-12-05 20:01   ` Heime
  2022-12-05 21:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2 siblings, 1 reply; 8+ messages in thread
From: Jean Louis @ 2022-12-05 19:42 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

* Heime <heimeborgia@protonmail.com> [2022-12-05 14:42]:
> 
> How can I set up an array of five elements in a let clause.
> 
>   (let ( (ss (nth 0 (decode-time)))    ; seconds
>          (mm (nth 1 (decode-time)))    ; minutes
>          (hh (nth 2 (decode-time)))    ; hours
>          (us (nth 2 (current-time)))   ; microsecond
>          (ps (nth 3 (current-time)))   ; picosecond
>          (lc (make-array '(5))) )

For array references, evaluate below functions:

(info "(elisp) Array Functions")

(info "(elisp) Sequences Arrays Vectors")

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: Defining an array in a let clause.
  2022-12-05 19:42 ` Jean Louis
@ 2022-12-05 20:01   ` Heime
  0 siblings, 0 replies; 8+ messages in thread
From: Heime @ 2022-12-05 20:01 UTC (permalink / raw)
  To: Jean Louis; +Cc: Heime via Users list for the GNU Emacs text editor


------- Original Message -------
On Monday, December 5th, 2022 at 7:42 PM, Jean Louis <bugs@gnu.support> wrote:


> * Heime heimeborgia@protonmail.com [2022-12-05 14:42]:
> 
> > How can I set up an array of five elements in a let clause.
> > 
> > (let ( (ss (nth 0 (decode-time))) ; seconds
> > (mm (nth 1 (decode-time))) ; minutes
> > (hh (nth 2 (decode-time))) ; hours
> > (us (nth 2 (current-time))) ; microsecond
> > (ps (nth 3 (current-time))) ; picosecond
> > (lc (make-array '(5))) )
> 
> 
> For array references, evaluate below functions:
> 
> (info "(elisp) Array Functions")
> 
> (info "(elisp) Sequences Arrays Vectors")

A vector solved it with (lc (make-vector 6 0))



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

* Re: Defining an array in a let clause.
  2022-12-05 11:40 Defining an array in a let clause Heime
  2022-12-05 12:54 ` Eli Zaretskii
  2022-12-05 19:42 ` Jean Louis
@ 2022-12-05 21:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-12-05 21:44 UTC (permalink / raw)
  To: help-gnu-emacs

>          (mm (nth 1 (decode-time)))    ; minutes
>          (hh (nth 2 (decode-time)))    ; hours

This may end up telling it's 14:59 whereas it's actually 14:00 (because
you were unlucky enough to call the first `decode-time` when it's still
13:59 and the second when we're now 14:00.

Rule of thumb: don't call twice a function unless there's a good reason
for it.  Instead store the result of the first call in a var and then
refer to that var.


        Stefan




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

end of thread, other threads:[~2022-12-05 21:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-05 11:40 Defining an array in a let clause Heime
2022-12-05 12:54 ` Eli Zaretskii
2022-12-05 13:56   ` Heime
2022-12-05 14:42     ` Eli Zaretskii
2022-12-05 18:12       ` Eduardo Ochs
2022-12-05 19:42 ` Jean Louis
2022-12-05 20:01   ` Heime
2022-12-05 21:44 ` Stefan Monnier via Users list for the GNU Emacs text editor

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.