HNHacker News
TopNewBestAskShowJobs

xisukar

190 karma · joined December 8, 2018

submissionscomments
xisukar··on I Don't Like Smartphones (2016)
> I do not have a phone number and I use a lower end Samsung basically as an ipod with wifi support. It constantly annoys me that apps that have no reason to require a phone number will not even let you register without one.

This is interesting. I've never had a cellphone plan myself, however given that some apps (e.g., Telegram) and job applications require a phone number as you say, I've been using a TextNow [1] phone number with the caveat of needing wifi/cellular data. As of now, the only thing that worries me a bit is when I'm out and I need to contact someone but I don't have wifi access.

So how do you go about without a phone (mainly for calls)?

[1] https://www.textnow.com/

xisukar··on [dead]

    Person: You know why I'm upset?! Because I think you patronize people and their
    viewpoints.

    Pinker: Well, son, let me you tell me about this study that suggests a reason
    why you feel that way.
xisukar··on Perl 6's given: switch on steroids
The `when` block seems to exhibit a different behavior when used as a block vs as a statement modifier. The latter lets things falls through until it matches the most general case. For instance, given

    class Audience {
        has $.number;
        has $.gender;
        has $.formality;
        has $.country;
    }
    
    my @vosotros = <Spain EquitorialGuinea WesternSahara>;
    
    my $audience = Audience.new:
     :number(100), :gender('feminine'),
     :formality('informal'), :country('Spain')
    ;
Contrast:

    my $message = do given (.number, .gender, .formality, .country given $audience) {
      when     1, 'masculine', 'informal', *              { '¿Cómo estás mi amigo?'    }
      when     1, 'masculine',   'formal', *              { '¿Cómo está el señor?'     }
      when     1, 'feminine',  'informal', *              { '¿Cómo estás mi amiga?'    }
      when     1, 'feminine',    'formal', *              { '¿Cómo está la señora?'    }
      when * > 1, 'feminine',  'informal', @vosotros.any  { '¿Cómo estáis mis amigas?' }
      when * > 1,  *,          'informal', @vosotros.any  { '¿Cómo estáis mis amigos?' }
      when * > 1,  *,                  * , *              { '¿Cómo están ustedes?'     }
    }

    say $message; #=> «¿Cómo estáis mis amigas?␤»
with this:

    my $message = do given (.number, .gender, .formality, .country given $audience) {
      '¿Cómo estás mi amigo?'     when     1, 'masculine', 'informal', *;
      '¿Cómo está el señor?'      when     1, 'masculine',   'formal', *;
      '¿Cómo estás mi amiga?'     when     1, 'feminine',  'informal', *;
      '¿Cómo está la señora?'     when     1, 'feminine',    'formal', *;
      '¿Cómo estáis mis amigas?'  when * > 1, 'feminine',  'informal', @vosotros.any;
      '¿Cómo estáis mis amigos?'  when * > 1,  *,          'informal', @vosotros.any;
      '¿Cómo están ustedes?'      when * > 1,  *,                  * , *;
    }
    
    say $message; #=> «¿Cómo están ustedes?␤»
xisukar··on Perl 6's given: switch on steroids
Do you mind explaining how is it related to the article? I'm genuinely interested.
xisukar··on Regolith Linux – A desktop with less visual bullshit
Anybody knows how to set up the `Mod + ?` shortcut to bring the shortcuts? Do they use a script for this?
xisukar··on Positional-only Parameters for Python
In Raku, parameters can be either positional or named parameters (declared with the colon-pair syntax). However, from what I understand, only positional parameters can be passed as positional and named parameters as named. The closest Raku subroutine to Python's `def fun(a, b, c=None)` would be:

    sub fun($a, $b, :$c) { }

    fun(1, 2)                # This works!
    fun(1, 2, 3)             # Error: Too many positionals passed...
    fun(:a(1), :b(2), :c(3)) # Error: Too few positionals passed...
    fun(:c(3), :a(1), :b(2)) # Same as before
    fun(:c(3), 1, 2)         # This works!
   
Positional parameters are required by default but they can be made optional by providing a default value in the subroutine's signature or by placing a `?` right after the parameter. However, much like Python, positional parameters must appear before optional parameters:

    sub fun($b, $a?, :$c) { }
    
    fun(1) # This works!
On the other hand, named parameter, as evidenced by the first code snippet, are optional. However, they can be made required by placing a `!` right after the parameter:

    sub fun($a, $b, :$c!) { }
    
    fun(1, 2)        # Error: Required named parameter 'c' not passed
    fun(1, 2, :c(3)) # This works!

Remaining arguments can be slurped by using slurpy parameters. In its most basic form, slurpy positional parameters are indicated with `A` followed by an array parameter:

    sub fun($a, $b, A@rest) { }
However, regardless of the structure of the arguments, they are flatten. This automatic flattening can be avoided by using `AA` instead. Or it can be done conditionally by using `+`: If there's a single argument, flaten it. Else, leave them alone.

Slurpy named parameters are indicated also with `A` followed by a hash parameter:

     sub fun(:$c, :$d, A%rest) { }
Both can be used in conjunction:

     sub fun($a, $b, :$c, :$d, A@rest, A%rest) { } # Or:
     sub fun($a, $b, A@rest, :$c, :$d, A%rest) { }
Edit: HN eats up the asterisks so using `A` to stand for asterisk.
xisukar··on Custom string delimiters in Swift 5
Nice catch!

It's quite easy to get them wrong since `q` is just a `q` short to be `qq`. ;)

xisukar··on Custom string delimiters in Swift 5
Perl 6 (Raku) takes it a little further with what's known as the Q lang[1]. In their most literal form possible, strings are created by using a Q followed by any pair delimiting surrounding the text.

    Q[This is a literal string.]        #=> This is a literal string.
    Q!The most literal-est of all.!     #=> The most literal-est of all.
    Q<So I say 'Hello'>                 #=> So I say 'Hello'
From there, adverbs are used to sort of expand a literal string's behavior. For example, `Q:q` (or its more verbose form, `Q:single`) means the string can interpolate \\, \qq[...] and escaping the delimiter with \.

    Q:q[A simple string]                #=> A simple string
    Q:q{Backslash: \}                   #=> Backslash: \
    Q:q!Backslash: \\!                  #=> Backslash: \
    Q:q{This is a \} so not too early.} #=> This is a } so not too early.
 
 
In the other hand, `Q:qq` (or `Q:double`) means the string can interpolate scalars (`$`), arrays (`@`), hashes (`%`), function calls (`&`), closure (`{...}`) and backslashes.

    my $bool = True;
    my @bools = True, False;
    my %bools = False => 0, True => 1;

    Q:qq[Scalar: $bool]                        #=> «Scalar: True»
    Q:qq{Array: @bools[]}                      #=> «Array: True False»
    Q:qq (Hash: %bools{})                      #=> «Hash: False	0␤True  1»
    Q:qq!Function: %bools.keys.join(' and ')!  #=> «Function: False and True»
    Q:qq<Expression: { 1.0 + 2.0 == 3.0 }>     #=> «Expression: True»
In order to prevent unwanted interpolation such as in "username@email.xyz" or "https://es.wikipedia.org/wiki/%C3%87", only scalar variables are interpolated normally. As demonstrated, the array constructor `[]` is used to interpolate a whole array , the hash constructor `{}` for a hash, etc.

Since both `Q:q` and `Q:qq` are so common in the language, they have more usual and succinct forms: single quotes (`''`) for `Q:q` and double quotes(`""`) for `Q:qq`. Furthermore the Q can be dropped so `q` or `qq` (followed by a delimiter) can be used as well.

From here onwards, a small number of adverbs can be used on the quoting constructs `q` or `qq` to further restrict/expand a string's behavior. For example, for a string that only interpolates scalar ($) and closure ({...}) variables, the adverbs `:s` (or `:scalar`) and `:c` (or `:closure`) can be used. This results in `qq:s:c` (or `qq:sc`, `qq:scalar:closure`). For example:

    my $var = 25;
    qq:s:c<$var: { 3**2 + 4**2 }> #=> «25: 25»
Another example is the use of `q` with the `:to` (or `:heredoc`) adverb which seems to be the closest construct to Swift 5's custom string delimiters:

    my $billTheCat = q:to/BILL/;
    <------- ____
      &&&    /    \  __ _____,
        `-- |  o   \'  `  &&/
           `|      | o  },-'
             \____( )__/
             ,'    \'   \
     /~~~~~~|.      |   .}~~~\
      ,-----( .     |   .}--.
            | .    /\___/
             `----^,\ \
                    \_/
    BILL
    
[1] https://docs.perl6.org/language/quoting
xisukar··on Haskell to Perl 6
> ...the several big or small mistakes I am about to make in the following.

Everything you wrote seems fine to me and you even expounded on what I wrote! However, even if it wasn't, I'd be hardly pressed to come up with a response as clever and resourceful as your responses. For this reason, I quite enjoy reading your comments whenever I come across them on /r/perl6 and /r/programminglanguages.

> Like a lot of P6 stuff this... is both childishly simple but also so general, abstract, and high level... that it can be difficult to explain.

You're totally spot on. The most recent example of my struggle (mainly due to my ignorance of Perl 6 and probably CS concepts too) was the concept of containers and how they interface most assignments in Perl 6. I think the fact that many Perl 6 constructs/concepts, which complex in nature, seem so natural can deceive people who haven't tried it yet. This is because it's easy to overlook (or plainly ignore) how much thought went into both integrating them into the language and make them play nicely together.

---

Thanks for your comments!

xisukar··on Haskell to Perl 6
You're totally right! I always get them confused. So `∈` is `(elem)` and `⊆` is `(<=)`.

Thanks for pointing it out!

xisukar··on Haskell to Perl 6
> In P6, every type that's created using any of its type constructors is a sum type with two sub-types. > This includes types defined in the standard language such as Int. The sub-types are named D and U. > For example, to refer to Int's D sub-type, use `Int:D`.

Probably your comment hints to this already in which case the following will be redundant but I wanted to mention them more explicitly. This is mainly for people unfamiliar with Perl 6.

Using the type smileys(:U, :D) are also ways to specifically match against a type object (`Int`, `Str`, `Rat`, etc.) and an instance object of a type object (-5, 'Hello', 1/5, etc.):

    Int ~~ Int:U;   # True
    -5  ~~ Int:U;   # False
    -5  ~~ Int:D;   # True
    Int ~~ Int:D;   # False
There is also the :_ smiley which is used by default whenever the other two aren't specified:

    Int ~~ Int;     # True, same as: Int ~~ Int:_;
    -5  ~~ Int;     # True, same as: -5  ~~ Int:_;
xisukar··on Haskell to Perl 6
From https://docs.perl6.org/routine/contains, `contains` coerces its invocant to a string and searches for a substring starting from a certain position (index 0 by default):

    # Let's drop `<>` (quote-words constructor) and 
    # use a more familiar array of strings:
      
    my @menu = 'hamburger', 'fries', 'milkshake';
      
    # Let's look at the definition of the `Str` method in 
    # the `List` class from which the `Array` class inherits:
    
    #`{
      method Str(List:D: --> Str:D)
      Stringifies the elements of the list and joins
      them with spaces (same as .join(' ')).
    }

    # Thus, after being stringfied, @menu is treated as 
    # the string 'hamburger fries milkshake'
    
    # With this is in hand, we can gauge the possible
    # result of the following statements:
    
    say @menu.contains('hamburger');            # True 
    say @menu.contains('hot dog');              # False 
    say @menu.contains('milk');                 # True
    say @menu.contains('er fr');                # True 
    say @menu.contains(<es mi>);                # True


If you'd like instead to search the array for words as elements, we could use Perl 6's set functions. However, I don't know if they're as performant as regular string searches:

    say 'hamburger' (<=) @menu;  # True 
    say 'fries' (<=) @menu;      # True 
    say 'hot dog' ∈ @menu;       # False 
    say 'milk' ∈ @menu;          # False 
    say 'er fr' ∈ @menu;         # False 
`∈` is the unicode equivalent of `(<=)`.

---

I'm not sure if I'm missing something in the "odd design choices" in this specific case so it'd be great if you could elaborate a little bit further here.

xisukar··on Haskell to Perl 6
> It is true that one can easily write unmaintainable spaghetti in Perl5.

This was something that surprised me when I first learned about Perl 5 in college. Most people in the internet would parrot it as a "write-only" language and yet I've always being capable of getting the whole picture of a code snippet posted on Perl Monks, Reddit, Stack Overflow, etc. Granted I've always steered away from golf code which obviously has its place but shouldn't be mistaken as being the "de facto way" of writing Perl 5 or Perl 6 for that matter.

xisukar··on Haskell to Perl 6
This would be one way to write in Perl 6:

    for @numbers -> $number {
        next unless $number > 10;
        next if $number %% 2;
        work($number);
    }
xisukar··on Haskell to Perl 6
As pointed out by others, Mu is the most undefined value there is in Perl 6 and the base root for the immediate child classes (https://docs.perl6.org/images/type-graph-Mu.svg). However, most classes (both built-in and user-defined ones) don't inherit directly from it. Instead, they inherit from Any, which in turns inherits from Mu.

More info about it:

- https://docs.perl6.org/type/Mu

- https://en.wikipedia.org/wiki/Mu_%28negative%29

xisukar··on Haskell to Perl 6
If I went on to learn about "Functors, Applicative Functors and Monoids" (which I'm completely ignorant about) in Haskell without having first learned Haskell's basic building blocks, then I would be disingenuous myself if I blamed the language for my ignorance and unfamiliarity with the language. On top of that, if you're not a Haskell user I don't think you're the target audience as pointed out by bmn__. For this reason, there are several migration guides (Python, Ruby, etc.) which ,although incomplete, they give the languages' respective users a contrast against Perl 6 which hopefully translates into some familiarity with it.

If you want to start from the bottom out, there's the ever improving language docs: https://docs.perl6.org/language.html

xisukar··on Haskell to Perl 6
As for the say function, it's also supposed to output text in a more human readable format. It calls the `.gist` of its argument, which you can override in user-defined classes. Take for example the following code snippet from Perl 6 Deep Dive:

    class Chemical { 
        has $.formula; 
        method gist { 
            my $output = $!formula; 
            $output ~~ s:g/(<[0..9]>)/{(0x2080+$0).chr}/; 
            $output; 
        }
     }


     my $chem = Chemical.new(formula => 'Al6O13Si2'); 
     say $chem; # Al₆O₁₃Si₂

     #`[
     Without overriding the `gist` method:

     say $chem; # Chemical.new(formula => 'Al6O13Si2')
     ]
← PreviousPage 2 of 2