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. |
|||
02:18
teatime left
02:19
teatime joined
02:33
teatwo joined
02:36
teatime left
02:51
MasterDuke left
06:11
human_blip left
06:12
human_blip joined
08:14
dakkar joined
09:59
razetime joined
10:48
razetime left
13:22
jgaz joined
14:18
tea3po joined
14:21
teatwo left,
pusha joined
|
|||
pusha | does Raku have object literals a la Javascript? | 14:22 | |
like | |||
const x= {a: 7} | |||
gfldex | m: constant x = class { has $.a is rw = 7 }; my %h = :a(7); dd x, %h; | 14:23 | |
camelia | <anon|1> Hash %h = {:a(7)} |
||
gfldex | pusha: not really, but ^^^ | ||
pusha | ok thanks | 14:24 | |
14:27
tea3po left
|
|||
lizmat | my constant x = { a => 7 } ?? | 14:27 | |
14:27
tea3po joined
|
|||
Nemokosch | the question is, which one is the important part: "object" or "literal" | 14:27 | |
gfldex | So, how constant do you want your constant to be? :-> | 14:31 | |
lizmat | my constant x = { a => 7 }.Map | 14:32 | |
my constant x = { a => 7 }.Map; x<a> = 42 # Cannot change key 'a' in an immutable Map | |||
14:37
tea3po left,
tea3po joined
|
|||
pusha | the constant part is not important | 14:38 | |
gfldex | pusha: Then you should use a Hash. | 14:41 | |
lizmat | is this maybe about aliasing a value in a hash to a variable? | 14:46 | |
m: my %h; my $a := %h<a>; dd %h; $a = 42; dd %h | |||
camelia | Hash %h = {} Hash %h = {:a(42)} |
||
16:39
dakkar left
18:20
pusha left
|
|||
librasteve | Hashes are mutable mappings from keys to values, known in other programming languages as dicts (Python), objects (Javascript) or Hash Maps (Java). | 21:13 | |
^^^ docs.raku.org/type/Hash | 21:14 | ||
so the equivalent to a JS object is a raku Hah | 21:15 | ||
m: my %h = :a(7); say %h<a> | 21:21 | ||
Raku eval | 7 |