Even Ruby's trailing blocks syntax are an homage to Perl's block list subroutines:
# first Ruby example in article
users.select { |u| u.admin? }.map(&:email)
# using Perl's block list
map {$_->email} grep {$_->is_admin} @users;4,727 karma · joined August 5, 2008
blog - http://transfixedbutnotdead.com
work - http://www.draegtun.com
twitter - http://twitter.com/draegtun
LinkedIn - http://www.linkedin.com/in/draegtun
github - https://github.com/draegtun
cpan - https://metacpan.org/author/DRAEGTUN
Even Ruby's trailing blocks syntax are an homage to Perl's block list subroutines:
# first Ruby example in article
users.select { |u| u.admin? }.map(&:email)
# using Perl's block list
map {$_->email} grep {$_->is_admin} @users; $hash1->{key1}{key2}
And if `hash1` was a hash (instead of a hashref) then it's just this: $hash1{key1}{key2}
The `%{}` de-reference you mention later is only when you have an operation that requires a hash, for eg: keys %{$hash1{key1}}
And for kstrauser example later in Python... hash1["hash_name"]["array_name"][3]
the equivalent in Perl would be... $hash1{hash_name}{array_name}[3]
I find having {} & [] as lookup keys for their types is not only more explicit but also safer/correct. # perl
my $x = do {
…
5
};
;; Rebol/Red
x: do [
…
5
]I remember comparing Tcl/Tk with Rebol/View - https://news.ycombinator.com/item?id=7069311
- Definitional Scoping / Rebol actually does not have scoping at all - https://stackoverflow.com/q/21964110/12195
- Bindology - https://en.wikibooks.org/wiki/Rebol_Programming/Advanced/Bin...
I totally agree and more so on ballards.
The hairs on my back of my neck always stand up when I hear I Keep A Close Watch (especially the M:FANS version [1], but the original Helen of Troy version is also great [2] and there's plenty of wonderful live versions).
[1] https://youtu.be/d7wBvyrao8I [2] https://youtu.be/LoggPfL3dLU
Or even one line :)
Factor...
: unless ( ? quot -- res ) swap [ drop ] [ call ] if ; inline
Rebol/Red... unless: func [expr block] [either expr [] block]I've seen it mentioned on Rebol chatter that Crockford approached Carl Sassenrath (creator of Rebol) to open-source & use Rebol prior to creating JSON. So having a Javascript literal wasn't on Crockford's mind at that point.
NB. Rebol was closed sourced until 2012.
user: [name: "John Doe" birth-date: 1970-01-01 account-balance: $1000.01]
[1] https://en.wikipedia.org/wiki/RebolA fly on the wall video of the 1st album [1] recording sessions was posted couple of years ago [2] which includes bits where you can see Sylvian/Sakamoto working together.
1: https://en.wikipedia.org/wiki/Brilliant_Trees
2: The Berlin Sessions - https://youtu.be/v-X36Xi8i58
And Factor and many implementations of Lisp too!
However there are some differences...
loop 10 [
print "hello" ;; prints "hello" 10 times
]
repeat n 10 [
print n ;; prints 1 to 10
]
forever [
print "hello" ;; print "hello" forever!
]Plight & Premonition - https://en.wikipedia.org/wiki/Plight_%26_Premonition
Flux + Mutability - https://en.wikipedia.org/wiki/Flux_%2B_Mutability
Couple of articles about their collaboration: https://pitchfork.com/reviews/albums/david-sylvian-holger-cz... | https://thequietus.com/articles/24916-david-sylvian-holger-c...
In Programming Perl it says "Associative Arrays" in 1st edition and "Hashes (Associative Arrays)" in 2nd edition.
NB. 2nd edition was the first to cover Perl5
There's probably a few different reasons to why but one thing that the 3 i've listed above all have in common is that they have image-based environments. So thats probably one of the top reasons why they have superior REPLs.
Arguments sent as `[blocks]` are always unevaluated but you can also explictly set a function argument to not be evaluated...
f: func ['a] [
print ["you gave me: " a]
print ["and this is what it evaluates to:" get a]
]
val: "hi!"
f val
Outputs: you gave me: val
and this is what it evaluates to: hi!
And the function body is mutable... f: func [a] [
print a
]
f 10 ;; => 10
append second :f [* 2]
f 10 ;; => 20This is how your example would look like in PARSE rule...
1 3 [{What is your } ["name" | "quest" | "favourite colour"] "?" opt space]And its easy to view the source code from the console (REPL). Some examples from Rebol2...
>> source func
func: func [
"Defines a user function with given spec and body."
[catch]
spec [block!] {Help string (opt) followed by arg words (and opt type and string)}
body [block!] "The body block of the function"
][
throw-on-error [make function! spec body]
]
>> source source
source: func [
"Prints the source code for a word."
'word [word!]
][
prin join word ": "
if not value? word [print "undefined" exit]
either any [native? get word op? get word action? get word] [
print ["native" mold third get word]
] [print mold get word]
]Or alternatively Rebol, which was one of the inspirations to JSON.
With Rebol you could write these patches like this:
patch [
replace /baz: "boo"
add /hello: ["world"]
remove /foo
]
patch [
add /biscuits/1: [name: "Ginger Nut"]
] my $double = sub {$_[0] * 2};
$double->(5);Here's the parse rule for Batman:
[
16 "na"
2 [space "batman"]
]
And complete example for the Semantic version: digit: charset "1234567890"
if parse "0.2.5" [
opt "v"
copy major [some digit]
"."
copy minor [some digit]
"."
copy patch [some digit]
][
print [major minor patch]
]This isn't unique to Ruby and is possible in other languages.
For eg. in Smalltalk you could create this DSL...
1 day ago.