Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Inverted-syntax/00-META.yaml
Normal file
2
Task/Inverted-syntax/00-META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Inverted_syntax
|
||||
22
Task/Inverted-syntax/00-TASK.txt
Normal file
22
Task/Inverted-syntax/00-TASK.txt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
'''Inverted syntax with conditional expressions'''
|
||||
|
||||
In traditional syntax conditional expressions are usually shown before the action within a statement or code block:
|
||||
|
||||
<syntaxhighlight lang="pseudocode"> IF raining=true THEN needumbrella=true </syntaxhighlight>
|
||||
|
||||
In inverted syntax, the action is listed before the conditional expression in the statement or code block:
|
||||
|
||||
<syntaxhighlight lang="pseudocode"> needumbrella=true IF raining=true </syntaxhighlight>
|
||||
|
||||
'''Inverted syntax with assignment'''
|
||||
|
||||
In traditional syntax, assignments are usually expressed with the variable appearing before the expression:
|
||||
|
||||
<syntaxhighlight lang="pseudocode"> a = 6</syntaxhighlight>
|
||||
|
||||
In inverted syntax, the expression appears before the variable:
|
||||
<syntaxhighlight lang="pseudocode"> 6 = a</syntaxhighlight>
|
||||
|
||||
'''Task'''
|
||||
|
||||
The task is to demonstrate support for inverted syntax forms within the language by showing both the traditional and inverted forms.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
loop_MySubroutine:
|
||||
; more than 127 bytes of code
|
||||
|
||||
dex
|
||||
bne loop_MySubroutine ;assembler will display an error message that the branch is too far away.
|
||||
; rest of program
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
loop_mySubroutine:
|
||||
; more than 127 bytes of code
|
||||
|
||||
dex
|
||||
beq continue
|
||||
JMP loop_mySubroutine
|
||||
continue:
|
||||
; rest of program
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
word $BEEF
|
||||
byte $EF,$BE
|
||||
29
Task/Inverted-syntax/ALGOL-68/inverted-syntax.alg
Normal file
29
Task/Inverted-syntax/ALGOL-68/inverted-syntax.alg
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Inverted assignment #
|
||||
# Assignment in Algol 68 is via ":=" which is automaically provided for all modes (types) #
|
||||
# However we could define e.g. "=:" as an inverted assignment operator but we would need to #
|
||||
# define a separate operator for each mode, e.g. for integers and strings: #
|
||||
PRIO =: = 1;
|
||||
OP =: = ( INT a, REF INT b )REF INT: b := a;
|
||||
OP =: = ( STRING a, REF STRING b )REF STRING: b := a;
|
||||
OP =: = ( CHAR a, REF STRING b )REF STRING: b := a;
|
||||
INT a, b; STRING s;
|
||||
1 =: a;
|
||||
a + 1 =: b;
|
||||
"?" =: s;
|
||||
print( ( a, b, s, newline ) );
|
||||
|
||||
# There is one standard inverted assignment operator: +=: or PLUSTO which prepends a string #
|
||||
# to another: #
|
||||
"bc" =: s;
|
||||
"b" +=: s;
|
||||
print( ( s, newline ) );
|
||||
|
||||
# Inverted Conditional Expressions #
|
||||
# We could define an operator called WHEN perhaps, that would execute its left operand if #
|
||||
# the right operand was TRUE. However the left operand would need to be a PROC VOID so the #
|
||||
# syntax would not be as convientent as the standard IF-THEN-FI construct. E.g.: #
|
||||
PRIO WHEN = 1;
|
||||
OP WHEN = ( PROC VOID code, BOOL test )VOID: IF test THEN code FI;
|
||||
|
||||
( VOID: print( ( "NO", newline ) ) ) WHEN a = b; # the anonymous PROC VOID is not called #
|
||||
( VOID: print( ( "yes", newline ) ) ) WHEN a /= b # the anonymous PROC VOID is called #
|
||||
2
Task/Inverted-syntax/ARM-Assembly/inverted-syntax-1.arm
Normal file
2
Task/Inverted-syntax/ARM-Assembly/inverted-syntax-1.arm
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
MOV R0,R3 ;copy R3 to R0
|
||||
ADD R2,R1,R5 ;add R1 to R5 and store the result in R2.
|
||||
1
Task/Inverted-syntax/ARM-Assembly/inverted-syntax-2.arm
Normal file
1
Task/Inverted-syntax/ARM-Assembly/inverted-syntax-2.arm
Normal file
|
|
@ -0,0 +1 @@
|
|||
STR r0,[r4] ;store the contents of R0 into the memory location specified by R4.
|
||||
2
Task/Inverted-syntax/ARM-Assembly/inverted-syntax-3.arm
Normal file
2
Task/Inverted-syntax/ARM-Assembly/inverted-syntax-3.arm
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
STMFD sp!,{r0-r12,lr} ;push r0 thru r12 and the link register
|
||||
LDMFD sp!,{r0-r12,pc} ;pop r0 thru r12, and the value that was in the link register is popped into the program counter.
|
||||
5
Task/Inverted-syntax/Ada/inverted-syntax.ada
Normal file
5
Task/Inverted-syntax/Ada/inverted-syntax.ada
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Foo := 1;
|
||||
loop
|
||||
exit when Foo = 10;
|
||||
Foo := Foo + 1;
|
||||
end loop;
|
||||
9
Task/Inverted-syntax/Arturo/inverted-syntax.arturo
Normal file
9
Task/Inverted-syntax/Arturo/inverted-syntax.arturo
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
ifStatement: function [block, condition][
|
||||
if condition -> do block
|
||||
]
|
||||
alias.infix {??} 'ifStatement
|
||||
|
||||
do [
|
||||
variable: true
|
||||
[print "Variable is true!"] ?? variable
|
||||
]
|
||||
3
Task/Inverted-syntax/Bracmat/inverted-syntax-1.bracmat
Normal file
3
Task/Inverted-syntax/Bracmat/inverted-syntax-1.bracmat
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
double=.!arg+!arg;
|
||||
|
||||
(=.!arg+!arg):(=?double); { inverted assignment syntax, same result as above. }
|
||||
2
Task/Inverted-syntax/Bracmat/inverted-syntax-2.bracmat
Normal file
2
Task/Inverted-syntax/Bracmat/inverted-syntax-2.bracmat
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
foo=3+7 { assigns 3+7 to foo }
|
||||
3+7:?foo { assigns 10 to foo }
|
||||
22
Task/Inverted-syntax/C++/inverted-syntax.cpp
Normal file
22
Task/Inverted-syntax/C++/inverted-syntax.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
class invertedAssign {
|
||||
int data;
|
||||
public:
|
||||
invertedAssign(int data):data(data){}
|
||||
int getData(){return data;}
|
||||
void operator=(invertedAssign& other) const {
|
||||
other.data = this->data;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main(){
|
||||
invertedAssign a = 0;
|
||||
invertedAssign b = 42;
|
||||
std::cout << a.getData() << ' ' << b.getData() << '\n';
|
||||
|
||||
b = a;
|
||||
|
||||
std::cout << a.getData() << ' ' << b.getData() << '\n';
|
||||
}
|
||||
16
Task/Inverted-syntax/C/inverted-syntax-1.c
Normal file
16
Task/Inverted-syntax/C/inverted-syntax-1.c
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define otherwise do { register int _o = 2; do { switch (_o) { case 1:
|
||||
#define given(Mc) ;case 0: break; case 2: _o = !!(Mc); continue; } break; } while (1); } while (0)
|
||||
|
||||
|
||||
int foo() { return 1; }
|
||||
|
||||
main()
|
||||
{
|
||||
int a = 0;
|
||||
|
||||
otherwise a = 4 given (foo());
|
||||
printf("%d\n", a);
|
||||
exit(0);
|
||||
}
|
||||
21
Task/Inverted-syntax/C/inverted-syntax-2.c
Normal file
21
Task/Inverted-syntax/C/inverted-syntax-2.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
main()
|
||||
{
|
||||
int a = 0;
|
||||
|
||||
do {
|
||||
register int _o = 2;
|
||||
do {
|
||||
switch (_o) {
|
||||
case 1:
|
||||
a = 4;
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
_o = !!(foo());
|
||||
continue;
|
||||
} break;
|
||||
} while (1);
|
||||
} while (0);
|
||||
printf("%d\n", a);
|
||||
exit(0);
|
||||
}
|
||||
12
Task/Inverted-syntax/Clojure/inverted-syntax-1.clj
Normal file
12
Task/Inverted-syntax/Clojure/inverted-syntax-1.clj
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
; normal
|
||||
(if (= 1 1)
|
||||
(print "Math works."))
|
||||
|
||||
; inverted
|
||||
(->> (print "Math still works.")
|
||||
(if (= 1 1)))
|
||||
|
||||
; a la Haskell
|
||||
(->> (print a " is " b)
|
||||
(let [a 'homoiconicity
|
||||
b 'awesome]))
|
||||
4
Task/Inverted-syntax/Clojure/inverted-syntax-2.clj
Normal file
4
Task/Inverted-syntax/Clojure/inverted-syntax-2.clj
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
((fn [x] (* x x) 5) ; Define a lambda and call it with 5.
|
||||
|
||||
(macroexpand-1 '(->> 5 (fn [x] (* x x))))
|
||||
(fn [x] (* x x) 5) ; Define a lambda that returns 5 regardless.
|
||||
2
Task/Inverted-syntax/Clojure/inverted-syntax-3.clj
Normal file
2
Task/Inverted-syntax/Clojure/inverted-syntax-3.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(= (mod (inc 42) 7)
|
||||
(-> 42 inc (mod 7)))
|
||||
8
Task/Inverted-syntax/CoffeeScript/inverted-syntax.coffee
Normal file
8
Task/Inverted-syntax/CoffeeScript/inverted-syntax.coffee
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
alert "hello" if true
|
||||
alert "hello again" unless false # the same as the above; unless is a negated if.
|
||||
|
||||
idx = 0
|
||||
arr = (++idx while idx < 10) # arr is [1,2,3,4,5,6,7,8,9,10]
|
||||
|
||||
idx = 0
|
||||
arr = (++idx until idx is 10) # same as above; until is an inverted while.
|
||||
10
Task/Inverted-syntax/Common-Lisp/inverted-syntax-1.lisp
Normal file
10
Task/Inverted-syntax/Common-Lisp/inverted-syntax-1.lisp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(eval-when (:compile-toplevel :load-toplevel :execute)
|
||||
(defun unrev-syntax (form)
|
||||
(cond
|
||||
((atom form) form)
|
||||
((null (cddr form)) form)
|
||||
(t (destructuring-bind (oper &rest args) (reverse form)
|
||||
`(,oper ,@(mapcar #'unrev-syntax args)))))))
|
||||
|
||||
(defmacro rprogn (&body forms)
|
||||
`(progn ,@(mapcar #'unrev-syntax forms)))
|
||||
14
Task/Inverted-syntax/Common-Lisp/inverted-syntax-2.lisp
Normal file
14
Task/Inverted-syntax/Common-Lisp/inverted-syntax-2.lisp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(eval-when (:compile-toplevel :load-toplevel :execute)
|
||||
(defun unrev-syntax (form)
|
||||
(cond
|
||||
((atom form) form) ;; atom: leave alone
|
||||
((null (cdr form)) form) ;; one-element form: leave alone
|
||||
((null (cddr form)) ;; two-element form: swap
|
||||
(destructuring-bind (arg oper) form
|
||||
`(,oper ,(unrev-syntax arg))))
|
||||
(t ;; two or more args: swap last two, add others in reverse
|
||||
(destructuring-bind (arg1 oper &rest args) (reverse form)
|
||||
`(,oper ,(unrev-syntax arg1) ,@(mapcar #'unrev-syntax args)))))))
|
||||
|
||||
(defmacro rprogn (&body forms)
|
||||
`(progn ,@(mapcar #'unrev-syntax forms)))
|
||||
14
Task/Inverted-syntax/D/inverted-syntax.d
Normal file
14
Task/Inverted-syntax/D/inverted-syntax.d
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/rdmd
|
||||
|
||||
import std.algorithm;
|
||||
|
||||
void main() {
|
||||
assert("Hello, World".length == 12);
|
||||
assert("Cleanliness".startsWith("Clean"));
|
||||
|
||||
auto r = [1, 4, 2, 8, 5, 7]
|
||||
.filter!(n => n > 2)
|
||||
.map!(n => n * 2);
|
||||
|
||||
assert(r.equal([8, 16, 10, 14]));
|
||||
}
|
||||
23
Task/Inverted-syntax/EchoLisp/inverted-syntax.l
Normal file
23
Task/Inverted-syntax/EchoLisp/inverted-syntax.l
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
;; use reader macros to transform (a OP b) into (OP b a)
|
||||
|
||||
(lib 'match)
|
||||
(define-macro invert-= (a <- b) (set! b a))
|
||||
(define-macro invert-IF (a 'IF b) (when b a))
|
||||
|
||||
(define raining #f)
|
||||
|
||||
(#t <- raining)
|
||||
raining
|
||||
→ #t
|
||||
('umbrella-need IF raining)
|
||||
→ umbrella-need
|
||||
|
||||
(#f <- raining)
|
||||
('umbrella-need IF raining)
|
||||
→ #f
|
||||
|
||||
;; debug mode
|
||||
(debug 3)
|
||||
('umbrella-need IF raining)
|
||||
💡 [0] invert-IF → ('umbrella-need IF raining)
|
||||
compiled :: (#when raining 'umbrella-need)
|
||||
4
Task/Inverted-syntax/Factor/inverted-syntax-1.factor
Normal file
4
Task/Inverted-syntax/Factor/inverted-syntax-1.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
1 1 + ! 2
|
||||
[ + 1 1 ] reverse call ! 2
|
||||
{ 1 2 3 4 5 } [ sq ] map ! { 1 4 9 16 25 }
|
||||
[ map [ sq ] { 1 2 3 4 5 } ] reverse call ! { 1 4 9 16 25 }
|
||||
3
Task/Inverted-syntax/Factor/inverted-syntax-2.factor
Normal file
3
Task/Inverted-syntax/Factor/inverted-syntax-2.factor
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
MACRO: pre ( quot -- quot ) reverse ;
|
||||
|
||||
[ + 2 2 ] pre ! 4
|
||||
1
Task/Inverted-syntax/Factor/inverted-syntax-3.factor
Normal file
1
Task/Inverted-syntax/Factor/inverted-syntax-3.factor
Normal file
|
|
@ -0,0 +1 @@
|
|||
[ + 3 + 2 2 ] pre ! 7
|
||||
3
Task/Inverted-syntax/Factor/inverted-syntax-4.factor
Normal file
3
Task/Inverted-syntax/Factor/inverted-syntax-4.factor
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
MACRO: pre ( quot -- quot ) 1 cut swap [ 0 ] dip reduce 1quotation ;
|
||||
|
||||
[ + 1 2 3 4 5 ] pre ! 15
|
||||
4
Task/Inverted-syntax/Factor/inverted-syntax-5.factor
Normal file
4
Task/Inverted-syntax/Factor/inverted-syntax-5.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
USE: infix
|
||||
[infix
|
||||
5*(1+1) ! 10
|
||||
infix]
|
||||
1
Task/Inverted-syntax/Fortran/inverted-syntax.f
Normal file
1
Task/Inverted-syntax/Fortran/inverted-syntax.f
Normal file
|
|
@ -0,0 +1 @@
|
|||
INQUIRE(FILE = FILENAME(1:L), EXIST = MAYBE, ERR = 666, IOSTAT = RESULT)
|
||||
13
Task/Inverted-syntax/FreeBASIC/inverted-syntax.basic
Normal file
13
Task/Inverted-syntax/FreeBASIC/inverted-syntax.basic
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
#Define ThenIf(a, b) If b Then a
|
||||
#Define InvertAssign(a, b) b = a
|
||||
|
||||
Dim As Boolean needUmbrella = False, raining = True
|
||||
ThenIf(needUmbrella = True, raining = True)
|
||||
Print "needUmbrella = "; needUmbrella
|
||||
|
||||
Dim As Integer b = 0, a = 3
|
||||
InvertAssign(a, b)
|
||||
Print "b is"; b
|
||||
Sleep
|
||||
30
Task/Inverted-syntax/Go/inverted-syntax.go
Normal file
30
Task/Inverted-syntax/Go/inverted-syntax.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type ibool bool
|
||||
|
||||
const itrue ibool = true
|
||||
|
||||
func (ib ibool) iif(cond bool) bool {
|
||||
if cond {
|
||||
return bool(ib)
|
||||
}
|
||||
return bool(!ib)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var needUmbrella bool
|
||||
raining := true
|
||||
|
||||
// normal syntax
|
||||
if raining {
|
||||
needUmbrella = true
|
||||
}
|
||||
fmt.Printf("Is it raining? %t. Do I need an umbrella? %t\n", raining, needUmbrella)
|
||||
|
||||
// inverted syntax
|
||||
raining = false
|
||||
needUmbrella = itrue.iif(raining)
|
||||
fmt.Printf("Is it raining? %t. Do I need an umbrella? %t\n", raining, needUmbrella)
|
||||
}
|
||||
2
Task/Inverted-syntax/Haskell/inverted-syntax-1.hs
Normal file
2
Task/Inverted-syntax/Haskell/inverted-syntax-1.hs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
when :: Monad m => m () -> Bool -> m ()
|
||||
action `when` condition = if condition then action else return ()
|
||||
2
Task/Inverted-syntax/Haskell/inverted-syntax-2.hs
Normal file
2
Task/Inverted-syntax/Haskell/inverted-syntax-2.hs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
func a b x = (x + y) / y
|
||||
where y = a * b
|
||||
3
Task/Inverted-syntax/Haskell/inverted-syntax-3.hs
Normal file
3
Task/Inverted-syntax/Haskell/inverted-syntax-3.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
func a b x =
|
||||
let y = a * b in
|
||||
(x + y) / y
|
||||
16
Task/Inverted-syntax/Haskell/inverted-syntax-4.hs
Normal file
16
Task/Inverted-syntax/Haskell/inverted-syntax-4.hs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import Data.Bool (bool)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let raining = False
|
||||
|
||||
putStrLn $ bool "No need" "UMBRELLA !" raining
|
||||
putStrLn $ flip bool "No need" "UMBRELLA !" raining
|
||||
|
||||
putStrLn "\n--------\n"
|
||||
|
||||
mapM_ putStrLn $
|
||||
[bool, flip bool]
|
||||
<*> ["No need"]
|
||||
<*> ["UMBRELLA !"]
|
||||
<*> [raining, not raining]
|
||||
5
Task/Inverted-syntax/Icon/inverted-syntax.icon
Normal file
5
Task/Inverted-syntax/Icon/inverted-syntax.icon
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
procedure main()
|
||||
raining := TRUE := 1 # there is no true/false null/non-null will do
|
||||
if \raining then needumbrella := TRUE # normal
|
||||
needumbrella := 1(TRUE, \raining) # inverted (choose sub-expression 1)
|
||||
end
|
||||
1
Task/Inverted-syntax/Jq/inverted-syntax-1.jq
Normal file
1
Task/Inverted-syntax/Jq/inverted-syntax-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
v as $x
|
||||
2
Task/Inverted-syntax/Jq/inverted-syntax-2.jq
Normal file
2
Task/Inverted-syntax/Jq/inverted-syntax-2.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
o["a"] = 2
|
||||
# or equivalently: o.a = 2
|
||||
7
Task/Inverted-syntax/Julia/inverted-syntax.julia
Normal file
7
Task/Inverted-syntax/Julia/inverted-syntax.julia
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
macro inv(expr, cond)
|
||||
cond isa Expr && cond.head == :if || throw(ArgumentError("$cond is not an if expression"))
|
||||
cond.args[2] = expr
|
||||
return cond
|
||||
end
|
||||
|
||||
@inv println("Wow! Lucky Guess!") if true else println("Not!") end
|
||||
9
Task/Inverted-syntax/Kotlin/inverted-syntax.kotlin
Normal file
9
Task/Inverted-syntax/Kotlin/inverted-syntax.kotlin
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// version 1.0.6
|
||||
|
||||
infix fun Boolean.iif(cond: Boolean) = if (cond) this else !this
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val raining = true
|
||||
val needUmbrella = true iif (raining)
|
||||
println("Do I need an umbrella? ${if(needUmbrella) "Yes" else "No"}")
|
||||
}
|
||||
10
Task/Inverted-syntax/Latitude/inverted-syntax-1.latitude
Normal file
10
Task/Inverted-syntax/Latitude/inverted-syntax-1.latitude
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
local 'raining = True.
|
||||
local 'needUmbrella = False.
|
||||
|
||||
if (raining) then {
|
||||
needUmbrella = True.
|
||||
} else {}.
|
||||
|
||||
{ raining. } ifTrue {
|
||||
needUmbrella = True.
|
||||
}.
|
||||
14
Task/Inverted-syntax/Latitude/inverted-syntax-2.latitude
Normal file
14
Task/Inverted-syntax/Latitude/inverted-syntax-2.latitude
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#'Method when := {
|
||||
localize.
|
||||
if ($1) then {
|
||||
this.
|
||||
} else { }.
|
||||
}.
|
||||
|
||||
#'Method unless := {
|
||||
#'self when ($1 not).
|
||||
}.
|
||||
|
||||
;; Example usage
|
||||
{ needUmbrella = True. } when (raining).
|
||||
{ needUmbrella = True. } unless (raining not).
|
||||
7
Task/Inverted-syntax/Latitude/inverted-syntax-3.latitude
Normal file
7
Task/Inverted-syntax/Latitude/inverted-syntax-3.latitude
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
global let= := { self slot ($2) = #'$1. }.
|
||||
|
||||
local 'a = 6.
|
||||
println: a. ;; 6
|
||||
|
||||
let 6 = 'b.
|
||||
println: b. ;; 6
|
||||
8
Task/Inverted-syntax/Lua/inverted-syntax.lua
Normal file
8
Task/Inverted-syntax/Lua/inverted-syntax.lua
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
a = {1,3,5,4,2} -- a "plain" table
|
||||
table.sort(a) -- library method passing a as param
|
||||
print(table.concat(a)) -- and again --> "12345"
|
||||
|
||||
b = {1,3,5,4,2} -- a "plain" table, so far..
|
||||
setmetatable(b, {__index=table}) -- ..but now "meta-decorated"
|
||||
b:sort() -- syntax sugar passes b as "self"
|
||||
print(b:concat()) -- and again --> "12345"
|
||||
54
Task/Inverted-syntax/M2000-Interpreter/inverted-syntax.m2000
Normal file
54
Task/Inverted-syntax/M2000-Interpreter/inverted-syntax.m2000
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
expr=lambda ->{
|
||||
Print "ok"
|
||||
}
|
||||
ifrev=lambda (dothis, cond) ->{
|
||||
if cond then call dothis()
|
||||
}
|
||||
a=1
|
||||
call ifrev(expr, a=1)
|
||||
|
||||
\\ on module call
|
||||
Module Subtract (a, b) {
|
||||
Push a-b
|
||||
}
|
||||
Module PrintTop {
|
||||
Print Number
|
||||
}
|
||||
Subtract 10, 3 : PrintTop
|
||||
\\ pushing before calling in reverse order
|
||||
Push 3, 10 : Subtract : PrintTop
|
||||
\\ Before call PrintTop any parameter send to stack
|
||||
\\ So this works ok
|
||||
PrintTop 1000
|
||||
\\ on assignment
|
||||
Dim A(5)=1
|
||||
Global n=2
|
||||
Function AddOne (x) {
|
||||
n++
|
||||
=x
|
||||
}
|
||||
\\ Execution of left expression, then right expression
|
||||
A(n)=AddOne(5)
|
||||
Print A(n-1)=5, n=3
|
||||
\\ Execution of right expression, then left expression
|
||||
Let A(n)=AddOne(15)
|
||||
Print A(n)=15, n=4
|
||||
\\ This statement..
|
||||
Let X=1, Y=2
|
||||
\\ executed like these
|
||||
Push 2, 1 : Read X, Y
|
||||
|
||||
\\ This is the CallBack way
|
||||
Module ExecCond {
|
||||
Read &callback(), cond
|
||||
if cond then call callback()
|
||||
}
|
||||
x=1
|
||||
\\ this aa() is a function but when we call it after transforming from Lazy$()
|
||||
\\ act as part of module so we see x, and alter it
|
||||
Function aa {
|
||||
x++
|
||||
}
|
||||
a=1
|
||||
ExecCond Lazy$(&aa()), A=1
|
||||
Print x=2
|
||||
6
Task/Inverted-syntax/M4/inverted-syntax.m4
Normal file
6
Task/Inverted-syntax/M4/inverted-syntax.m4
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
define(`thenif', `ifelse($2, $3, `$1')')dnl
|
||||
dnl
|
||||
ifelse(eval(23 > 5), 1, 23 is greater than 5)
|
||||
ifelse(eval(23 > 5), 0, math is broken)
|
||||
thenif(23 is greater than 5, eval(23 > 5), 1)
|
||||
thenif(math is broken, eval(23 > 5), 0)
|
||||
10
Task/Inverted-syntax/Mathematica/inverted-syntax.math
Normal file
10
Task/Inverted-syntax/Mathematica/inverted-syntax.math
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
a = 4
|
||||
->4
|
||||
|
||||
b = 5
|
||||
->5
|
||||
|
||||
If[1<2,
|
||||
Print["This was expected"]
|
||||
]
|
||||
->This was expected
|
||||
8
Task/Inverted-syntax/Mercury/inverted-syntax-1.mercury
Normal file
8
Task/Inverted-syntax/Mercury/inverted-syntax-1.mercury
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
:- pred progress(int::in, int::in, int::out, int::out) is det.
|
||||
progress(Past, Future, At, Total) :-
|
||||
At = Past + 1,
|
||||
Total = Past + Future.
|
||||
|
||||
progress(Past, Future, At, Total) :-
|
||||
Past + Future = Total,
|
||||
Past + 1 = At.
|
||||
8
Task/Inverted-syntax/Mercury/inverted-syntax-2.mercury
Normal file
8
Task/Inverted-syntax/Mercury/inverted-syntax-2.mercury
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
:- func example(int) = string.
|
||||
example(N) = S :-
|
||||
from_int(N) = S0,
|
||||
pad_left(S0, '0', 3, S).
|
||||
|
||||
example(N) = S :-
|
||||
pad_left(S0, '0', 3, S),
|
||||
from_int(N) = S0.
|
||||
7
Task/Inverted-syntax/Mercury/inverted-syntax-3.mercury
Normal file
7
Task/Inverted-syntax/Mercury/inverted-syntax-3.mercury
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
main(IO0, IO) :-
|
||||
io.write_string("Hello, ", IO0, IO1),
|
||||
io.write_string("world!\n", IO1, IO).
|
||||
|
||||
main(!IO) :-
|
||||
io.write_string("Hello, ", !IO),
|
||||
io.write_string("world!\n", !IO).
|
||||
13
Task/Inverted-syntax/Mercury/inverted-syntax-4.mercury
Normal file
13
Task/Inverted-syntax/Mercury/inverted-syntax-4.mercury
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
main(!IO) :-
|
||||
io.write_string(X, !IO), io.nl(!IO),
|
||||
some_long_uninteresting_thing(X).
|
||||
|
||||
% this is the same:
|
||||
main(!IO) :-
|
||||
some_long_uninteresting_thing(X),
|
||||
io.write_string(X, !IO), io.nl(!IO).
|
||||
|
||||
% but this is different!
|
||||
main(!IO) :-
|
||||
io.nl(!IO), io.write_string(X, !IO),
|
||||
some_long_uninteresting_thing(X).
|
||||
2
Task/Inverted-syntax/Metafont/inverted-syntax.metafont
Normal file
2
Task/Inverted-syntax/Metafont/inverted-syntax.metafont
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
x=6;
|
||||
7=y;
|
||||
31
Task/Inverted-syntax/Nim/inverted-syntax.nim
Normal file
31
Task/Inverted-syntax/Nim/inverted-syntax.nim
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#--
|
||||
# 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
|
||||
17
Task/Inverted-syntax/OxygenBasic/inverted-syntax.basic
Normal file
17
Task/Inverted-syntax/OxygenBasic/inverted-syntax.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
macro cond(a,c) {c then a}
|
||||
|
||||
macro store(b,a) {a=b}
|
||||
|
||||
sys a,c=10
|
||||
|
||||
if c>4 then a=4
|
||||
|
||||
'INVERTED SYNTAX FORMS:
|
||||
|
||||
cond a=40, if c>4
|
||||
|
||||
store 4,a
|
||||
|
||||
'COMBINED:
|
||||
|
||||
cond store(5,a), if c>4
|
||||
4
Task/Inverted-syntax/PARI-GP/inverted-syntax.parigp
Normal file
4
Task/Inverted-syntax/PARI-GP/inverted-syntax.parigp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fi(f, condition)=if(condition,f());
|
||||
|
||||
if(raining, print("Umbrella needed"))
|
||||
fi(->print("Umbrella needed"), raining)
|
||||
4
Task/Inverted-syntax/Perl/inverted-syntax-1.pl
Normal file
4
Task/Inverted-syntax/Perl/inverted-syntax-1.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
if ($guess == 6) { print "Wow! Lucky Guess!"; }; # Traditional syntax
|
||||
print 'Wow! Lucky Guess!' if $guess == 6; # Inverted syntax (note missing braces and parens)
|
||||
unless ($guess == 6) { print "Sorry, your guess was wrong!"; } # Traditional syntax
|
||||
print 'Huh! You Guessed Wrong!' unless $guess == 6; # Inverted syntax
|
||||
4
Task/Inverted-syntax/Perl/inverted-syntax-2.pl
Normal file
4
Task/Inverted-syntax/Perl/inverted-syntax-2.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Note that the results obtained by the inverted syntax form
|
||||
# may produce differing results from the traditional syntax form
|
||||
$a = $ok ? $b : $c; # Traditional syntax
|
||||
($ok ? $b : $c) = $a; # Inverted syntax
|
||||
3
Task/Inverted-syntax/Perl/inverted-syntax-3.pl
Normal file
3
Task/Inverted-syntax/Perl/inverted-syntax-3.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
sub assign { $_[1] = $_[0] }
|
||||
$a = $b; # Traditional syntax
|
||||
assign $b, $a; # Inverted syntax
|
||||
20
Task/Inverted-syntax/Phix/inverted-syntax-1.phix
Normal file
20
Task/Inverted-syntax/Phix/inverted-syntax-1.phix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(notonline)-->
|
||||
<span style="color: #008080;">if</span> <span style="color: #008080;">end</span>
|
||||
<span style="color: #0000FF;">(&</span><span style="color: #008000;">"test.exw"</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span><span style="color: #000000;">cl</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">system</span>
|
||||
<span style="color: #008080;">then</span> <span style="color: #0000FF;">></span><span style="color: #000000;">2</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cl</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">length</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #0000FF;">(&</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pgm</span><span style="color: #0000FF;">)</span><span style="color: #000000;">mung</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"test.exw"</span><span style="color: #0000FF;">)</span><span style="color: #000000;">write_file</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
|
||||
<span style="color: #000000;">write_file</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> <span style="color: #008080;">include</span>
|
||||
<span style="color: #0000FF;">([$]</span><span style="color: #000000;">cl</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">get_text</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">pgm</span> <span style="color: #004080;">string</span>
|
||||
<span style="color: #0000FF;">()</span><span style="color: #7060A8;">command_line</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cl</span> <span style="color: #004080;">sequence</span>
|
||||
<span style="color: #008080;">function</span> <span style="color: #008080;">end</span>
|
||||
<span style="color: #0000FF;">(</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">join</span> <span style="color: #008080;">return</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #008080;">end</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">nup</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rip</span><span style="color: #0000FF;">,((([</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">substitute_all</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span><span style="color: #000000;">lines</span> <span style="color: #008080;">do</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">length</span> <span style="color: #008080;">to</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">=</span><span style="color: #000000;">i</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #0000FF;">((</span><span style="color: #008000;">"\r\n"</span><span style="color: #0000FF;">,(</span><span style="color: #000000;">rip</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pun</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pgm</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">=</span><span style="color: #000000;">lines</span> <span style="color: #004080;">sequence</span>
|
||||
<span style="color: #0000FF;">(</span><span style="color: #000000;">pgm</span> <span style="color: #004080;">string</span><span style="color: #0000FF;">)</span><span style="color: #000000;">mung</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">,(</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" -<>{}@! "</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">split</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">rip</span> <span style="color: #008080;">constant</span>
|
||||
<span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">,(</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"-,=][)("</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">split</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">nup</span> <span style="color: #008080;">constant</span>
|
||||
<span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">,(</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"-,=[]()"</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">)</span><span style="color: #7060A8;">split</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">pun</span> <span style="color: #008080;">constant</span>
|
||||
<span style="color: #008080;">js without</span>
|
||||
<span style="color: #000000;">demo</span><span style="color: #0000FF;">\</span><span style="color: #000000;">rosetta</span><span style="color: #0000FF;">\</span><span style="color: #000000;">inverted_syntax</span><span style="color: #0000FF;">.</span><span style="color: #000000;">exw</span> <span style="color: #000080;font-style:italic;">--</span>
|
||||
<!--
|
||||
20
Task/Inverted-syntax/Phix/inverted-syntax-2.phix
Normal file
20
Task/Inverted-syntax/Phix/inverted-syntax-2.phix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(notonline)-->
|
||||
<span style="color: #000080;font-style:italic;">-- demo\rosetta\inverted_syntax.exw</span>
|
||||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span>
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">pun</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"()[]=,-"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">nup</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #008000;">")(][=,-"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">rip</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #008000;">" <>{}@!- "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">mung</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">pgm</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">lines</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pgm</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pun</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rip</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"\r\n"</span><span style="color: #0000FF;">))</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> <span style="color: #000000;">lines</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]))),</span><span style="color: #000000;">rip</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nup</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">cl</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">command_line</span><span style="color: #0000FF;">()</span>
|
||||
<span style="color: #004080;">string</span> <span style="color: #000000;">pgm</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_text</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cl</span><span style="color: #0000FF;">[$])</span>
|
||||
<span style="color: #008080;">include</span> <span style="color: #000000;">write_file</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
|
||||
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">write_file</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"test.exw"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">mung</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pgm</span><span style="color: #0000FF;">)&</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cl</span><span style="color: #0000FF;">)></span><span style="color: #000000;">2</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #7060A8;">system</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]&</span><span style="color: #008000;">"test.exw"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<!--
|
||||
2
Task/Inverted-syntax/PicoLisp/inverted-syntax.l
Normal file
2
Task/Inverted-syntax/PicoLisp/inverted-syntax.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(de rv Prg
|
||||
(append (last Prg) (head -1 Prg)) )
|
||||
1
Task/Inverted-syntax/PowerShell/inverted-syntax-1.psh
Normal file
1
Task/Inverted-syntax/PowerShell/inverted-syntax-1.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
if ((Get-Date 5/27/2016).DayOfWeek -eq "Friday") {"Thank God it's Friday!"}
|
||||
8
Task/Inverted-syntax/PowerShell/inverted-syntax-2.psh
Normal file
8
Task/Inverted-syntax/PowerShell/inverted-syntax-2.psh
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
function Action ([scriptblock]$Expression, [Alias("if")][bool]$Test)
|
||||
{
|
||||
if ($Test) {&$Expression}
|
||||
}
|
||||
|
||||
Set-Alias -Name say -Value Action
|
||||
|
||||
say {"Thank God it's Friday!"} -if (Get-Date 5/27/2016).DayOfWeek -eq "Friday"
|
||||
7
Task/Inverted-syntax/Prolog/inverted-syntax.pro
Normal file
7
Task/Inverted-syntax/Prolog/inverted-syntax.pro
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
% Dracula is a vampire.
|
||||
% Also, you become a vampire if someone who is a vampire bites you.
|
||||
vampire(dracula).
|
||||
vampire(You) :- bites(Someone, You), vampire(Someone).
|
||||
|
||||
% Oh no! Dracula just bit Bob...
|
||||
bites(dracula, bob).
|
||||
1
Task/Inverted-syntax/Python/inverted-syntax-1.py
Normal file
1
Task/Inverted-syntax/Python/inverted-syntax-1.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
x = truevalue if condition else falsevalue
|
||||
2
Task/Inverted-syntax/Python/inverted-syntax-2.py
Normal file
2
Task/Inverted-syntax/Python/inverted-syntax-2.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
with open("file.txt") as f:
|
||||
something(f)
|
||||
27
Task/Inverted-syntax/Qi/inverted-syntax.qi
Normal file
27
Task/Inverted-syntax/Qi/inverted-syntax.qi
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
(define set-needumbrella
|
||||
Raining -> (set needumbrella true) where (= true Raining)
|
||||
Raining -> (set needumbrella false) where (= false Raining))
|
||||
|
||||
(define set-needumbrella
|
||||
Raining -> (if (= true Raining)
|
||||
(set needumbrella true)
|
||||
(set needumbrella false)))
|
||||
|
||||
|
||||
Alternatives:
|
||||
|
||||
(define set-needumbrella
|
||||
Raining -> (set needumbrella true) where Raining
|
||||
Raining -> (set needumbrella false))
|
||||
|
||||
(define set-needumbrella
|
||||
Raining -> (if Raining
|
||||
(set needumbrella true)
|
||||
(set needumbrella false)))
|
||||
|
||||
(define set-needumbrella
|
||||
true -> (set needumbrella true)
|
||||
false -> (set needumbrella false))
|
||||
|
||||
(define set-needumbrella
|
||||
A -> (set needumbrella A))
|
||||
1
Task/Inverted-syntax/R/inverted-syntax-1.r
Normal file
1
Task/Inverted-syntax/R/inverted-syntax-1.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
do.if <- function(expr, cond) if(cond) expr
|
||||
1
Task/Inverted-syntax/R/inverted-syntax-2.r
Normal file
1
Task/Inverted-syntax/R/inverted-syntax-2.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
do.if(print("Wow! Lucky Guess!"), guess==6)
|
||||
3
Task/Inverted-syntax/R/inverted-syntax-3.r
Normal file
3
Task/Inverted-syntax/R/inverted-syntax-3.r
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
`%if%` <- function(expr, cond) if(cond) expr
|
||||
|
||||
print("Wow! Lucky Guess!") %if% (guess==6)
|
||||
10
Task/Inverted-syntax/REXX/inverted-syntax.rexx
Normal file
10
Task/Inverted-syntax/REXX/inverted-syntax.rexx
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/*REXX program demonstrates a use of a special case of inverted syntax (via SIGNAL ON).*/
|
||||
signal on syntax
|
||||
a=7
|
||||
zz=444 / (7-a)
|
||||
return zz
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
syntax: say '***error*** program is attempting to do division by zero,'
|
||||
say 'the REXX statement number is: ' sigL " and the REXX source is:"
|
||||
say sourceLine(sigL)
|
||||
exit 13
|
||||
7
Task/Inverted-syntax/Racket/inverted-syntax.rkt
Normal file
7
Task/Inverted-syntax/Racket/inverted-syntax.rkt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#lang racket
|
||||
(when #t (displayln "true"))
|
||||
((displayln "true") . when . #t)
|
||||
|
||||
(define a 6)
|
||||
(set! a 5)
|
||||
(a . set! . 6)
|
||||
4
Task/Inverted-syntax/Raku/inverted-syntax-1.raku
Normal file
4
Task/Inverted-syntax/Raku/inverted-syntax-1.raku
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
if $guess == 6 { say "Wow! Lucky Guess!" } # Traditional
|
||||
say 'Wow! Lucky Guess!' if $guess == 6; # Inverted
|
||||
unless $guess == 6 { say "Huh! You Guessed Rong!" } # Traditional
|
||||
say 'Huh! You Guessed Rong!' unless $guess == 6; # Inverted
|
||||
8
Task/Inverted-syntax/Raku/inverted-syntax-2.raku
Normal file
8
Task/Inverted-syntax/Raku/inverted-syntax-2.raku
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
while $i { --$i }
|
||||
--$i while $i;
|
||||
|
||||
until $x > 10 { $x++ }
|
||||
$x++ until $x > 10;
|
||||
|
||||
for 1..10 { .say if $_ %% 2 }
|
||||
.say if $_ %% 2 for 1..10; # list comprehension
|
||||
1
Task/Inverted-syntax/Raku/inverted-syntax-3.raku
Normal file
1
Task/Inverted-syntax/Raku/inverted-syntax-3.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
42 R= $_; say $_; # prints 42
|
||||
2
Task/Inverted-syntax/Raku/inverted-syntax-4.raku
Normal file
2
Task/Inverted-syntax/Raku/inverted-syntax-4.raku
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
my @a = 1,2,3;
|
||||
(1,2,3) R= my @a;
|
||||
2
Task/Inverted-syntax/Raku/inverted-syntax-5.raku
Normal file
2
Task/Inverted-syntax/Raku/inverted-syntax-5.raku
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
my @a <== 1,2,3;
|
||||
1,2,3 ==> my @a;
|
||||
7
Task/Inverted-syntax/Raku/inverted-syntax-6.raku
Normal file
7
Task/Inverted-syntax/Raku/inverted-syntax-6.raku
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
repeat {
|
||||
$_ = prompt "Gimme a number: ";
|
||||
} until /^\d+$/;
|
||||
|
||||
repeat until /^\d+$/ {
|
||||
$_ = prompt "Gimme a number: ";
|
||||
}
|
||||
3
Task/Inverted-syntax/Raku/inverted-syntax-7.raku
Normal file
3
Task/Inverted-syntax/Raku/inverted-syntax-7.raku
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
repeat until my $answer ~~ 42 {
|
||||
$answer = prompt "Gimme an answer: ";
|
||||
}
|
||||
4
Task/Inverted-syntax/Raku/inverted-syntax-8.raku
Normal file
4
Task/Inverted-syntax/Raku/inverted-syntax-8.raku
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
my $answer;
|
||||
repeat {
|
||||
$answer = prompt "Gimme an answer: ";
|
||||
} until $answer ~~ 42;
|
||||
15
Task/Inverted-syntax/Ruby/inverted-syntax.rb
Normal file
15
Task/Inverted-syntax/Ruby/inverted-syntax.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Raise ArgumentError if n is negative.
|
||||
if n < 0 then raise ArgumentError, "negative n" end
|
||||
raise ArgumentError, "negative n" if n < 0
|
||||
|
||||
# Exit 1 unless we can call Process.fork.
|
||||
unless Process.respond_to? :fork then exit 1 end
|
||||
exit 1 unless Process.respond_to? :fork
|
||||
|
||||
# Empty an array, printing each element.
|
||||
while ary.length > 0 do puts ary.shift end
|
||||
puts ary.shift while ary.length > 0
|
||||
|
||||
# Another way to empty an array, printing each element.
|
||||
until ary.empty? do puts ary.shift end
|
||||
puts ary.shift until ary.empty?
|
||||
6
Task/Inverted-syntax/Scala/inverted-syntax.scala
Normal file
6
Task/Inverted-syntax/Scala/inverted-syntax.scala
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
object Main extends App {
|
||||
|
||||
val raining = true
|
||||
val needUmbrella = raining
|
||||
println(s"Do I need an umbrella? ${if (needUmbrella) "Yes" else "No"}")
|
||||
}
|
||||
8
Task/Inverted-syntax/Sidef/inverted-syntax.sidef
Normal file
8
Task/Inverted-syntax/Sidef/inverted-syntax.sidef
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Inverted syntax with assignment
|
||||
var raining = true;
|
||||
[false]»(\var needumbrella);
|
||||
|
||||
# Inverted syntax with conditional expressions
|
||||
if (raining==true) {needumbrella=true};
|
||||
{needumbrella=true} -> if (raining==true);
|
||||
(needumbrella=true) if (raining==true);
|
||||
29
Task/Inverted-syntax/Swift/inverted-syntax.swift
Normal file
29
Task/Inverted-syntax/Swift/inverted-syntax.swift
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
infix operator ~= {}
|
||||
infix operator ! {}
|
||||
|
||||
func ~=(lhs:Int, inout rhs:Int) {
|
||||
rhs = lhs
|
||||
}
|
||||
|
||||
func !(lhs:(() -> Void), rhs:Bool) {
|
||||
if (rhs) {
|
||||
lhs()
|
||||
}
|
||||
}
|
||||
|
||||
// Traditional assignment
|
||||
var a = 0
|
||||
|
||||
// Inverted using a custom operator
|
||||
20 ~= a
|
||||
|
||||
let raining = true
|
||||
let tornado = true
|
||||
var needUmbrella = false
|
||||
var stayInside = false
|
||||
|
||||
// Traditional conditional expression
|
||||
if raining {needUmbrella = true}
|
||||
|
||||
// Inverted using a custom operator
|
||||
_ = {stayInside = true} ! tornado
|
||||
1
Task/Inverted-syntax/TI-83-BASIC/inverted-syntax.basic
Normal file
1
Task/Inverted-syntax/TI-83-BASIC/inverted-syntax.basic
Normal file
|
|
@ -0,0 +1 @@
|
|||
536→N
|
||||
84
Task/Inverted-syntax/Tcl/inverted-syntax-1.tcl
Normal file
84
Task/Inverted-syntax/Tcl/inverted-syntax-1.tcl
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
# do.tcl --
|
||||
#
|
||||
# Tcl implementation of a "do ... while|until" loop.
|
||||
#
|
||||
# Originally written for the "Texas Tcl Shootout" programming contest
|
||||
# at the 2000 Tcl Conference in Austin/Texas.
|
||||
#
|
||||
# Copyright (c) 2001 by Reinhard Max <Reinhard.Max@gmx.de>
|
||||
#
|
||||
# See the file "license.terms" for information on usage and redistribution
|
||||
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
#
|
||||
# RCS: @(#) $Id: do.tcl,v 1.6 2004/01/15 06:36:12 andreas_kupries Exp $
|
||||
#
|
||||
namespace eval ::control {
|
||||
|
||||
proc do {body args} {
|
||||
|
||||
#
|
||||
# Implements a "do body while|until test" loop
|
||||
#
|
||||
# It is almost as fast as builtin "while" command for loops with
|
||||
# more than just a few iterations.
|
||||
#
|
||||
|
||||
set len [llength $args]
|
||||
if {$len !=2 && $len != 0} {
|
||||
set proc [namespace current]::[lindex [info level 0] 0]
|
||||
return -code error "wrong # args: should be \"$proc body\" or \"$proc body \[until|while\] test\""
|
||||
}
|
||||
set test 0
|
||||
foreach {whileOrUntil test} $args {
|
||||
switch -exact -- $whileOrUntil {
|
||||
"while" {}
|
||||
"until" { set test !($test) }
|
||||
default {
|
||||
return -code error \
|
||||
"bad option \"$whileOrUntil\": must be until, or while"
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
# the first invocation of the body
|
||||
set code [catch { uplevel 1 $body } result]
|
||||
|
||||
# decide what to do upon the return code:
|
||||
#
|
||||
# 0 - the body executed successfully
|
||||
# 1 - the body raised an error
|
||||
# 2 - the body invoked [return]
|
||||
# 3 - the body invoked [break]
|
||||
# 4 - the body invoked [continue]
|
||||
# everything else - return and pass on the results
|
||||
#
|
||||
switch -exact -- $code {
|
||||
0 {}
|
||||
1 {
|
||||
return -errorinfo [ErrorInfoAsCaller uplevel do] \
|
||||
-errorcode $::errorCode -code error $result
|
||||
}
|
||||
3 {
|
||||
# FRINK: nocheck
|
||||
return
|
||||
}
|
||||
4 {}
|
||||
default {
|
||||
return -code $code $result
|
||||
}
|
||||
}
|
||||
# the rest of the loop
|
||||
set code [catch {uplevel 1 [list while $test $body]} result]
|
||||
if {$code == 1} {
|
||||
return -errorinfo [ErrorInfoAsCaller while do] \
|
||||
-errorcode $::errorCode -code error $result
|
||||
}
|
||||
return -code $code $result
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#usage:
|
||||
package require control
|
||||
control::do {set i 0; puts "hello world"; incr i} until {$i > 0}
|
||||
12
Task/Inverted-syntax/Tcl/inverted-syntax-2.tcl
Normal file
12
Task/Inverted-syntax/Tcl/inverted-syntax-2.tcl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
rename unknown __unknown
|
||||
proc unknown {args} {
|
||||
if {3 == [llength $args]} {
|
||||
package require control
|
||||
return [control::do {*}$args]
|
||||
} else {
|
||||
return [__unknown {*}$args]
|
||||
}
|
||||
}
|
||||
#usage
|
||||
% {set i 0; puts "hello world"; incr i} until {$i > 0}
|
||||
hello world
|
||||
8
Task/Inverted-syntax/Wortel/inverted-syntax.wortel
Normal file
8
Task/Inverted-syntax/Wortel/inverted-syntax.wortel
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
; a = expr
|
||||
:a expr
|
||||
; expr = a
|
||||
~:expr a
|
||||
; if cond expr
|
||||
@if cond expr
|
||||
; if expr cond
|
||||
~@if expr cond
|
||||
22
Task/Inverted-syntax/Wren/inverted-syntax.wren
Normal file
22
Task/Inverted-syntax/Wren/inverted-syntax.wren
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
class IBool {
|
||||
construct new(b) {
|
||||
if (!(b is Bool)) Fiber.abort("B must be a boolean")
|
||||
_b = b
|
||||
}
|
||||
|
||||
iff(cond) { cond ? _b : !_b }
|
||||
}
|
||||
|
||||
var itrue = IBool.new(true)
|
||||
|
||||
var needUmbrella
|
||||
var raining = true
|
||||
|
||||
// normal syntax
|
||||
if (raining) needUmbrella = true
|
||||
System.print("Is it raining? %(raining). Do I need an umbrella? %(needUmbrella)")
|
||||
|
||||
// inverted syntax
|
||||
raining = false
|
||||
needUmbrella = itrue.iff(raining)
|
||||
System.print("Is it raining? %(raining). Do I need an umbrella? %(needUmbrella)")
|
||||
2
Task/Inverted-syntax/Z80-Assembly/inverted-syntax.z80
Normal file
2
Task/Inverted-syntax/Z80-Assembly/inverted-syntax.z80
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
byte &EF,&BE
|
||||
word &BEEF
|
||||
2
Task/Inverted-syntax/Zkl/inverted-syntax-1.zkl
Normal file
2
Task/Inverted-syntax/Zkl/inverted-syntax-1.zkl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
if (raining==True) needumbrella:=True;
|
||||
(raining==True) : if (_) needumbrella:=True;
|
||||
2
Task/Inverted-syntax/Zkl/inverted-syntax-2.zkl
Normal file
2
Task/Inverted-syntax/Zkl/inverted-syntax-2.zkl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a := 6
|
||||
6 : a:=_
|
||||
2
Task/Inverted-syntax/Zkl/inverted-syntax-3.zkl
Normal file
2
Task/Inverted-syntax/Zkl/inverted-syntax-3.zkl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
key.sort(fcn(kv,kv2){kv[0] < kv2[0]}) : listUnzip(_) :
|
||||
D.SD((_).xplode()) : return(_);
|
||||
Loading…
Add table
Add a link
Reference in a new issue