Re: missing block
On 3/3/24 04:25, Elizabeth Mattijsen wrote: On 3 Mar 2024, at 05:12, ToddAndMargo via perl6-users wrote: $ raku -I./ -c CobianWrapper.pl6 Missing block at /home/CDs/Windows/NtUtil/CobianWrapper.pl6:1000 1000 is the last line in my code. I presume by "block" they mean something like "]" or "}" Do I really have to read 1000 lines of code to find my screw up? Anyone have a tip on how to find it quicker? I use `vim` as the editor. In `vim` if I have this situation, then I put the cursor on the first opening { and press `%`. This brings me to the corresponding closing }. If the associated closing curly does not match your expectations, then you're nearing the source of the problem. I assume other code editor have a similar `%` functionality. Hi Elizabeth, I learned vi about 35 years ago. I still use it occasionally. I will have to try out that % feature out. Thank you! (I just made a quick "Keeper" out of it.) I use Geany for programming a lot. Primarily as is works well with ssh X11 over poor internet connections. Geany has a thing were you park on a bracket of some type and it will turn the other end blue. So, something similar to vi (an alias to vim). To work around the missing block issue, I always place both sides of a {} before writing inside them. It does not always work if I ramble too much. And it is the tip off that I have rambled on too much and need to put some things into subs. Considering I am a YUGE proponent of "top down" programming, I really should know better. This is what became of your help: sub SortList( @List, Str $Msg, Bool $NoDebug ) { my @Sorted = Empty; @Sorted = @List.sort(*.split(/\d+/, :kv).map({ (try .Numeric) // $_}).List); if %Options< Debug > && not $NoDebug { print "$Msg"; for @Sorted.kv -> $Index, $Element { print " Element [$Index] <$Element>\n"; } } return @Sorted; } sub ListParentDir( Str $Msg, Bool $NoDebug = False ) { # list and sort %Options my @List = Empty; for dir( %Options ) { push @List, $_.Str }; @List = SortList @List, $Msg, $NoDebug; return @List; } It really cut down on the clutter and made missing bracket much easier to find. Oh and you helped me fix a bug in my program that I had though was a Windows error that had been going on for years. Thank you again! -T
Re: pint: Elizabeth, sort list???
> On 3 Mar 2024, at 03:32, ToddAndMargo via perl6-users > wrote: > >> On 3/2/24 05:13, Elizabeth Mattijsen wrote: >>> .sort(*.split(/\d+/, :kv).map({ (try .Numeric) // $_}).List) > >> Hi Elizabeth, >> It works perfectly. Thank you! >> I have no idea why, I will ask you in another post > Would you take apart your sort piece by piece and explain > each part? Actually, the expression can be refined a bit: say .sort(*.split(/\d+/, :v).map({ (try .Int) // $_}).List) Sort works by using `cmp` semantics by default. If `cmp` is called on two lists, it will `cmp` each element and return the result of the first comparison that did not produce `Same`. If you call `sort` with a Callable that takes only one argument, it is taken as the producer of the actual values that will be compared, basically doing a Schwartzian transform under the hood. A whatever code (which is what we specified here) produces a Callable with a single argument. So we'll be doing a Schwartzian transform under the hood. The `split` splits the value (each element in the list) on any set of Numeric characters (`\d+`), *but* also produces the strings that were split on (`:v`). (The previous version had .kv, but that just produces more identical entries in the list, which only will make comparisons slower). The resulting values from the `split` are then mapped to an integer value (if possible: `(try .Int)` and if that fails, just returns the value (`// $_`). (The previous version had `.Numeric`, which will also work, but since `\d+` can only produce integers, it's an extra unnecessary step). Then convert the `.Seq` that is produced by the `.map` to a `List`. Otherwise we'd be comparing `Seq` objects, and the semantics of those are undefined. So for `"afoo12" cmp "afoo2"`, we will be doing `("afoo", 12) cmp ("afoo", 2)`. Which would do: `"afoo" cmp "afoo"`, which produces `Same`, and then do `12 cmp 2`, which will return `More`, and thus will cause swapping the order of . Hope that made sense!