Jump to content

Inverted syntax: Difference between revisions

Added Nim example
(Added Nim example)
Line 686:
io.nl(!IO), io.write_string(X, !IO),
some_long_uninteresting_thing(X).</lang>
 
=={{header|Nim}}==
 
Inverted syntax in Nim can be achieved through the use of templates as operators:
 
<lang nim>#--
# if statements
#--
 
template `?`(expression, condition) =
if condition:
expression
 
let raining = true
var needUmbrella: bool
 
# Normal syntax
if raining: needUmbrella = true
 
# Inverted syntax
(needUmbrella = true) ? (raining == true)
 
#--
# Assignments
#--
 
template `~=`(right, left) =
left = right
 
var a = 3
 
# Normal syntax
a = 6
 
# Inverted syntax
6 ~= a</lang>
 
=={{header|Oforth}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.