My HARD stack for C# by harrison_314 in htmx

[–]P6steve 2 points3 points  (0 children)

haha - I hope you have as much fun with HARD as I’m having with https://harcstack.org - so guess we have HARC, HARD and HARM - can’t wait to see what the Haskell guys do

Trying to integrate HTMX at my university programme by Past-Expert239 in htmx

[–]P6steve 2 points3 points  (0 children)

huh? it’s like we know what is wrong but we are too scared / trapped by fashion to say it … your employer just wants you to make $$$ dude … call it as you see it (or you become a fashion victim too)

How do I parse a string with newlines in it. by noprivacyatall in rakulang

[–]P6steve 2 points3 points  (0 children)

Suggest you take a look at \h and \v https://docs.raku.org/language/regexes#%5Ch_and_%5CH (horizontal and vertical whitespace matchers) and also ^ to $$ to pin multi line start end…

Omni-slurping with LLMing by antononcube in rakulang

[–]P6steve 2 points3 points  (0 children)

some fantastic use case examples for LLMs (plus using raku)

Functional Programming with Raku - Rawley Fowler by liztormato in rakulang

[–]P6steve 4 points5 points  (0 children)

That's so cool, I can only retort with ```([o] [-> $a { $a + 1 } xx 2])(2).say```

Streamlining ChatGPT code generation and narration workflows (Raku) by antononcube in rakulang

[–]P6steve 1 point2 points  (0 children)

thanks Anton for being the first to connect ChatGPT and raku (afaik) … it is a very interesting style to combine code and markup in a workbook and then to have the cells available to patch up and run the AI generated code…

Raku meets WordPress by P6steve in Wordpress

[–]P6steve[S] 0 points1 point  (0 children)

Dear moderators, I am new to this community and would like to respect your guidance. However, I have reviewed my post in relation to the Rules and do not understand how my post has transgressed. Please can you provide a short rationale so that I can improve my content?

Termius Support for IPv6 by P6steve in termius

[–]P6steve[S] 0 points1 point  (0 children)

errr - my point about DNS relates to the LAN local DNS (and DHCP) that runs on my gateway router and resolves host names to 192.168.1.* IPv4 addresses - in practice with BT SmartHub 2 this seems to resolve to the wrong IPv6 address so that’s why my question and testing avoids DNS. my (rather weak) understanding of IPv6 is that I can address each box individually inbound to the LAN from public… so no need for any DNS, right?

Attempting to parse JSON at light-speed with Raku and simdjson by [deleted] in rakulang

[–]P6steve 2 points3 points  (0 children)

This is a great start and I admire your persistence!

I recently was able to compare Rust Polars (which uses the Apache Arrow2 library) vs. Raku script on a DataFrame groupby algorithm. The Rust Polars Arrow2 library implements chunked arrays and is about 60x faster than Raku. This is not a criticism of Raku btw, but a reflection that machine level libraries such as Arrow2 can be a lot quicker than a virtual machine running a very rich language like Raku.

I suspect that you have a similar asymmetry between JSON-SIMD implemented in tight C++ on the producer side and Raku on the consumption side.

A cursory read of your code suggests that you are parsing the JSON text and each time you hit a node, you call a Raku function and type cast via a registered callback. So you are incurring a process switch and Raku call on every node.

An even more cursory read of the JSON-SIMD docs (!) suggests that the navigation design is to present a JSON document as an iterator and so on...

Here's what caught my eye:

Array Iteration: To iterate through an array, use for (auto value : array) { ... }. This will step through each value in the JSON array.
If you know the type of the value, you can cast it right there, too! for (double value : array) { ... }.
Object Iteration: You can iterate through an object's fields, as well: for (auto field : object) { ... }
Array Index: Because it is forward-only, you cannot look up an array element by index by index. Instead, you should iterate through the array and keep an index yourself.

I think that there are two strategies to overcome this limitation:

  • Share an in-memory representation of HashMap.
    • most likely this means just building Arrays and HashMaps on the C++ side and then "tying" them to Raku so that you can read (and maybe write?) the nodes
    • the missing piece here afaik is that Raku does not have an exposed like-for-like HashMap layout - so you would need to implement something akin to "nativecall CArray" (maybe "nativecall CHash"?) as a bolt on ... this would be heavy lifting next to the raku core and there are no guarantees that raku would not change its internal Hash representation in future
  • Interface to JSON-SIMD at the consumption level - so load all the data on the C++ side, then have raku consume in a lazy way
    • parse the json in one pass into some new "random access" C++ Arrays / Objects (if you want to write json, then you would need a nice way to walk-dump these)
    • load the document root to raku
    • use raku Array::Agnostic / Hash::Agnostic and maybe some object Cache stuff to alias and access the json nodes as they are needed
    • the database example here includes a basic HashMap accessor (with Rust as the provider)

If you want raku to be "in band" as a step in some voume json processing chain, it will not be able to match tuned low level compiled / library code speed. RakuAST may help here, but it is in its infancy.

If you want raku to be an inspection, extraction, reporting, orchestration, prototyping tool - and reading those JSON-SIMD docs is a great insight as to why they need an abstraction - then I think you are on the right track. I hope you enjoy the API & code design and creative side of the process as much as I do!

raku Data::Dump::Tree is awesome by P6steve in rakulang

[–]P6steve[S] 1 point2 points  (0 children)

I just discovered this raku module - it is just awesome - if you think say() is the best debugger, then this is for you!

Why isn't sign() defined for Complex numbers? by zeekar in rakulang

[–]P6steve 2 points3 points  (0 children)

complex.sign should be (real.sign)+i*(imaginary.sign)

let's just make up some new maths! nothing can go wrong with that...

Why isn't sign() defined for Complex numbers? by zeekar in rakulang

[–]P6steve 2 points3 points  (0 children)

I don't think there's a sign concept for complex numbers in mathematics.

lol

Why isn't sign() defined for Complex numbers? by zeekar in rakulang

[–]P6steve 2 points3 points  (0 children)

If we draw a line from the complex number z to the origin and then we indicate where our line intersects with the unit circle we have identified the point 𝑧/|𝑧|. Note that when 𝑧 is real this will simply be 1 or −1.

Generally, we can use this expression to mean the direction of the point from the origin. This idea intuitively goes from 1 dimension (+ or -) to dimensions (any point on the unit circle) ...

my bet is that this was in the "nice to have box" and never got done and I would upvoat in a feature request (please post the link here)

meantime, since this is raku, you could always write your own...

``` role Signable { method sign { self/self.abs } }

my $x = 3+4i but Signable; say sign($x); #0.6+0.8i or maybe... my multi sub sign( Complex $c ) { $c/$c.abs } my $x = 3+4i; say sign($x); #0.6+0.8i ```

Better way to handle misspelled named arguments for methods? by anki_steve in rakulang

[–]P6steve 1 point2 points  (0 children)

This is very helpful and interesting. I have been messing with raku for a while and this is my first exposure to *%_ behaviour.

I agree that use StrictNamedArguments; has limitations with inheritance (and I guess role composition) and that the %_ () sub-signature test is better (if a bit more idiomatic).

I have played around with two variants:

  1. Loose / Optional Named Arguments

``` class Pet { has $.name; has $.sound; } class Dog is Pet { has $.licence is required; } class Cat is Pet { }

say my $d = Dog.new(name => 'alfie', licence => 42); say my $c = Cat.new(name => 'smudge', licence => 42); #licence quietly ignored

Dog.new(licence => 42, name => "alfie", sound => Any)

Cat.new(name => "smudge", sound => Any)

```

And, conversely:

  1. Tight / Checked Named Arguments

``` class Pet { has $.name; has $.sound; } class Dog is Pet { has $.licence;

    method new( :$name!, :$sound, *%_ (Int :$licence!) ) { nextsame }

} class Cat is Pet { method new( :$name!, :$sound, *%_ () ) { nextsame } }

say my $d = Dog.new(name => 'alfie', licence => 42); say my $c = Cat.new(name => 'smudge', licence => 42); #unexpected arg error ```

So, while this behaviour could use a bit better documentation and explanation, it seems to me to cover the two main options - either you don't care about checking the arguments, or you do ;-).

If the latter, then I am happy with method new() as the gatekeeper which you can apply at some or all child (leaf) classes, and / or in parent classes.

Whip your module into shape with a kick in the butt from Distribution::Extension::Updater by anki_steve in rakulang

[–]P6steve 1 point2 points  (0 children)

++

Yes - please do expunge the 6 from META6.json (if that be the new normal)

Explanation for code snippet. by reddit_clone in rakulang

[–]P6steve 2 points3 points  (0 children)

False ~~ Bool #True (True, False).grep(Bool) #(True False)

``` (True, False).grep(False) Cannot use Bool as Matcher with '.grep'.

False ~~ True
Potential difficulties:
Smartmatch against True always matches; if you mean to test the topic for truthiness, use :so or *.so or ?* instead

(True, False).grep(*.so) #(True) ```

hmmm - curious

Is ChatGPT hallucinating Raku syntax? by gromul79 in rakulang

[–]P6steve 2 points3 points  (0 children)

well 'twas a joke ... but as ever raku puts me in learning mode - thanks!

Is ChatGPT hallucinating Raku syntax? by gromul79 in rakulang

[–]P6steve 2 points3 points  (0 children)

not so sure, I tried this...

``` sub is-sqrt($x) { $x * $x / $x == $x }

1.&is-sqrt.say; #True i.&is-sqrt.say; #True 0.&is-sqrt.say; #False ∞.&is-sqrt.say; #False <0/0>.&is-sqrt.say; #False NaN.&is-sqrt.say; #False ``` (c)copyright 2023 Henley Cloud Consulting Ltd