This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html Set by lizmat on 8 June 2022. |
|||
aloussase | what is the equivalent of haskell cons operator in raku? | 01:32 | |
to add an item to the start or end of a list returning the new list | |||
MasterDuke | m: my @a = 1, 3; my @b = |@a, 4; dd @b; dd @a | 02:01 | |
camelia | Array @b = [1, 3, 4] Array @a = [1, 3] |
||
MasterDuke | m: my @a = 1, 3; my @b = (@a.flat, 4).flat; dd @b; dd @a | 02:03 | |
camelia | Array @b = [1, 3, 4] Array @a = [1, 3] |
||
antononcube | @aloussase Please give a LISP interpretation of what you asking. | ||
aloussase | I guess in LISP that would be literally cons, though my lisp is a bit rusty | 02:04 | |
02:31
Summer left,
Summer joined
|
|||
antononcube | I was mostly joking. | 02:33 | |
I thin you can to use .append and .prepend. | |||
04:32
camelia left
04:38
camelia joined
|
|||
librasteve | alousasse: in raku there are several classes that represent an ordered set of elements - Seq, List and Array - are the most common, As with much of raku, the functionality is stacked (using Positional & Iterator roles) which you can see from the TypeGraph here docs.raku.org/type/Array#typegraphrelations | 08:29 | |
My guess is that you looked at the class List page in the raku docs docs.raku.org/type/List and thus couldn't see the append prepend methods, | 08:30 | ||
That's because Array is a mutable List and is the place for all mutating operations which you can see in the methods list (open the content pane) in the class Array page here docs.raku.org/type/Array#method_append ... | 08:31 | ||
There are some other cool features that raku Arrays bring as the most "advanced" variant. For example, an array has it's own sigil and literal syntax. And it can hold typed elements as in my Int @a = [1,2,3] and this brings a lot of nice features such as multi-dimensions, shape and so on. In contrast a List is (usually) stored in a scalar container like my $l = 1,2,3 | 08:35 | ||
That said, you may not want all this and prefer an immutable (functional) approach with Lists (that's fine too ... this is raku, you get to choose!) | 08:36 | ||
So to (finally) answer your first question, to append or prepend a value to a List, you make a new List (since the List is immutable) like this: | 08:37 | ||
dd my $l1 = (1,2,3); dd my $l2 = (|$l1, 4); dd my $l3 = (0, |$l2); | 08:48 | ||
11:51
Summer left,
Summer joined
12:21
Summer left
12:22
Summer joined
13:23
Summer left,
Summer joined
13:54
Summer left,
Summer joined
14:24
Summer left
14:25
Summer joined
14:55
Summer left,
Summer joined
15:26
Summer left,
Summer joined
15:56
Summer left
15:57
Summer joined
16:27
Summer left,
Summer joined
16:58
Summer left,
Summer joined
17:28
Summer left
17:29
Summer joined
17:59
Summer left,
Summer joined
18:30
Summer left,
Summer joined
19:00
Summer left
19:01
Summer joined
19:31
Summer left,
Summer joined
20:02
Summer left,
Summer joined
20:32
Summer left
20:33
Summer joined
21:03
Summer left,
Summer joined
21:34
Summer left,
Summer joined
22:04
Summer left
22:05
Summer joined
22:12
Summer left
23:06
Summer joined
|