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
antononcube I was mostly joking. 02:33
I thin you can to use .append and .prepend.
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