Hacker News new | comments | show | ask | jobs | submit login

No it doesn't have the same flexibility.

Perl 6's string quoting sub language has various feature flags that you can turn on or off.

Here are a few of the basic ones shown in valid code (comments and newlines included)

  # start quoting with no features enabled
  # (not even backslashing the delimiter is enabled)
  Q

    :scalar    # enable $foo
    :array     # enable @foo[]
    :hash      # enable %foo{}
    :closure   # enable { 12/3 }
    :function  # enable &foo('bar')
    :single    # turns on backslashing the delimiter
    :backslash # enable \n
  
    :!exec     # turn off executing it (redundant)
    :exec(0)   # another syntax for turning off a feature
  
  {…}          # various delimiters are allowed (generally punctuation)
There are shorter variants of each of the feature flags. :c => :closure

I would like to point out that the parsing of the :closure and :function part of the sub language is reentrant. (Actually most of them add some form of reentrancy, it is just harder to show it for the others)

  "a b &foo( "c d &bar( "baz" )" )"
Note that this reuses the base Perl 6 parser, and that is why it is reentrant.

There are shortcuts for regularly used forms

  「」 =:= Q[]
  
  '' =:=  q[] =:= Q:q[]  =:= Q:single[]
  
  "" =:= qq[] =:= Q:qq[] =:= Q:double[]
     =:= Q:b:s:a:h:c:f[]
     =:= Q:backslash:scalar:array:hash:closure:function[]
The ability to turn off features can be useful

  qq :!c [a {\n  b\n} c] # { and } don't form a closure here
I would like to point out that the :foo syntax is used everywhere in the language for named parameters to routines and operators (most operators are implemented as subroutines)

  :foo =:= :foo( True ) =:= foo => True
  
  :!bar =:= :bar( False ) =:= bar => False
  
  :$baz =:= :baz( $baz ) =:= baz => $baz
If the delimiters are paired () <> {} 「」 «» “” ‘’ you can double up on them.

  q<FOO> =:= q<<FOO>> =:= q<<<<<FOO>>>>>
This is useful to avoid having to backslash a delimiter within the string, or trying to find a delimiter that isn't in the string.

  q<< <a> >> =:= q' <a> '



Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: