Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
16
Task/Metaprogramming/FreeBASIC/metaprogramming.freebasic
Normal file
16
Task/Metaprogramming/FreeBASIC/metaprogramming.freebasic
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
#Macro ForAll(C, S)
|
||||
For _i as integer = 0 To Len(s)
|
||||
#Define C (Chr(s[_i]))
|
||||
#EndMacro
|
||||
|
||||
#Define In ,
|
||||
|
||||
Dim s As String = "Rosetta"
|
||||
ForAll(c in s)
|
||||
Print c; " ";
|
||||
Next
|
||||
|
||||
Print
|
||||
Sleep
|
||||
3
Task/Metaprogramming/Lingo/metaprogramming.lingo
Normal file
3
Task/Metaprogramming/Lingo/metaprogramming.lingo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
r = RETURN
|
||||
str = "on halt"&r&"--do nothing"&r&"end"
|
||||
new(#script).scripttext = str
|
||||
11
Task/Metaprogramming/Nim/metaprogramming-1.nim
Normal file
11
Task/Metaprogramming/Nim/metaprogramming-1.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
proc `^`*[T: SomeInteger](base: T, exp: T): T =
|
||||
var (base, exp) = (base, exp)
|
||||
result = 1
|
||||
|
||||
while exp != 0:
|
||||
if (exp and 1) != 0:
|
||||
result *= base
|
||||
exp = exp shr 1
|
||||
base *= base
|
||||
|
||||
echo 2 ^ 10 # 1024
|
||||
6
Task/Metaprogramming/Nim/metaprogramming-2.nim
Normal file
6
Task/Metaprogramming/Nim/metaprogramming-2.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
when defined windows:
|
||||
echo "Call some Windows specific functions here"
|
||||
elif defined linux:
|
||||
echo "Call some Linux specific functions here"
|
||||
else:
|
||||
echo "Code for the other platforms"
|
||||
2
Task/Metaprogramming/Nim/metaprogramming-3.nim
Normal file
2
Task/Metaprogramming/Nim/metaprogramming-3.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
static:
|
||||
echo "Hello Compile time world: ", 2 ^ 10
|
||||
1
Task/Metaprogramming/Nim/metaprogramming-4.nim
Normal file
1
Task/Metaprogramming/Nim/metaprogramming-4.nim
Normal file
|
|
@ -0,0 +1 @@
|
|||
const x = 2 ^ 10
|
||||
14
Task/Metaprogramming/Nim/metaprogramming-5.nim
Normal file
14
Task/Metaprogramming/Nim/metaprogramming-5.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import os
|
||||
|
||||
const debug = false
|
||||
|
||||
proc expensive: string =
|
||||
sleep(milsecs = 100)
|
||||
result = "That was difficult"
|
||||
|
||||
proc log(msg: string) =
|
||||
if debug:
|
||||
echo msg
|
||||
|
||||
for i in 1..10:
|
||||
log expensive()
|
||||
6
Task/Metaprogramming/Nim/metaprogramming-6.nim
Normal file
6
Task/Metaprogramming/Nim/metaprogramming-6.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
template log(msg: string) =
|
||||
if debug:
|
||||
echo msg
|
||||
|
||||
for i in 1..10:
|
||||
log expensive()
|
||||
7
Task/Metaprogramming/Nim/metaprogramming-7.nim
Normal file
7
Task/Metaprogramming/Nim/metaprogramming-7.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
template times(x: expr, y: stmt): stmt =
|
||||
for i in 1..x:
|
||||
y
|
||||
|
||||
10.times: # or times 10:
|
||||
echo "hi"
|
||||
echo "bye"
|
||||
15
Task/Metaprogramming/Nim/metaprogramming-8.nim
Normal file
15
Task/Metaprogramming/Nim/metaprogramming-8.nim
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
template optLog1{a and a}(a): auto = a
|
||||
template optLog2{a and (b or (not b))}(a,b): auto = a
|
||||
template optLog3{a and not a}(a: int): auto = 0
|
||||
|
||||
var
|
||||
x = 12
|
||||
s = x and x
|
||||
# Hint: optLog1(x) --> ’x’ [Pattern]
|
||||
|
||||
r = (x and x) and ((s or s) or (not (s or s)))
|
||||
# Hint: optLog2(x and x, s or s) --> ’x and x’ [Pattern]
|
||||
# Hint: optLog1(x) --> ’x’ [Pattern]
|
||||
|
||||
q = (s and not x) and not (s and not x)
|
||||
# Hint: optLog3(s and not x) --> ’0’ [Pattern]
|
||||
13
Task/Metaprogramming/Nim/metaprogramming-9.nim
Normal file
13
Task/Metaprogramming/Nim/metaprogramming-9.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import macros
|
||||
|
||||
dumpTree:
|
||||
if x:
|
||||
if y:
|
||||
p0
|
||||
else:
|
||||
p1
|
||||
else:
|
||||
if y:
|
||||
p2
|
||||
else:
|
||||
p3
|
||||
5
Task/Metaprogramming/Ring/metaprogramming-1.ring
Normal file
5
Task/Metaprogramming/Ring/metaprogramming-1.ring
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
o1 = new point { x=10 y=20 z=30 }
|
||||
addmethod(o1,"print", func { see x + nl + y + nl + z + nl } )
|
||||
o1.print()
|
||||
Class point
|
||||
x y z
|
||||
44
Task/Metaprogramming/Ring/metaprogramming-2.ring
Normal file
44
Task/Metaprogramming/Ring/metaprogramming-2.ring
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
New App
|
||||
{
|
||||
I want window
|
||||
The window title = "hello world"
|
||||
}
|
||||
|
||||
Class App
|
||||
|
||||
func geti
|
||||
if nIwantwindow = 0
|
||||
nIwantwindow++
|
||||
ok
|
||||
|
||||
func getwant
|
||||
if nIwantwindow = 1
|
||||
nIwantwindow++
|
||||
ok
|
||||
|
||||
func getwindow
|
||||
if nIwantwindow = 2
|
||||
nIwantwindow= 0
|
||||
see "Instruction : I want window" + nl
|
||||
ok
|
||||
if nWindowTitle = 0
|
||||
nWindowTitle++
|
||||
ok
|
||||
|
||||
func settitle cValue
|
||||
if nWindowTitle = 1
|
||||
nWindowTitle=0
|
||||
see "Instruction : Window Title = " + cValue + nl
|
||||
ok
|
||||
|
||||
private
|
||||
|
||||
# Attributes for the instruction I want window
|
||||
i want window
|
||||
nIwantwindow = 0
|
||||
# Attributes for the instruction Window title
|
||||
# Here we don't define the window attribute again
|
||||
title
|
||||
nWindowTitle = 0
|
||||
# Keywords to ignore, just give them any value
|
||||
the=0
|
||||
8
Task/Metaprogramming/Shen/metaprogramming-1.shen
Normal file
8
Task/Metaprogramming/Shen/metaprogramming-1.shen
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(define make-list
|
||||
[A|D] -> [cons (make-list A) (make-list D)]
|
||||
X -> X)
|
||||
|
||||
(defmacro info-macro
|
||||
[info Exp] -> [output "~A: ~A~%" (make-list Exp) Exp])
|
||||
|
||||
(info (* 5 6)) \\ outputs [* 5 6]: 30
|
||||
7
Task/Metaprogramming/Shen/metaprogramming-2.shen
Normal file
7
Task/Metaprogramming/Shen/metaprogramming-2.shen
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(0-) (defmacro +-macro
|
||||
[A + B] -> [+ A B])
|
||||
macro
|
||||
+-macro
|
||||
|
||||
(1-) (1 + (* 2 3))
|
||||
7
|
||||
14
Task/Metaprogramming/Shen/metaprogramming-3.shen
Normal file
14
Task/Metaprogramming/Shen/metaprogramming-3.shen
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(2-) (tc +)
|
||||
true
|
||||
|
||||
(3+) (+ 1 2 3)
|
||||
6 : number
|
||||
|
||||
(4+) +
|
||||
+ : (number --> (number --> number))
|
||||
|
||||
(5-) (tc -)
|
||||
false
|
||||
|
||||
(6-) (macroexpand [+ 1 2 3])
|
||||
[+ 1 [+ 2 3]]
|
||||
7
Task/Metaprogramming/Sidef/metaprogramming-1.sidef
Normal file
7
Task/Metaprogramming/Sidef/metaprogramming-1.sidef
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class Number {
|
||||
method ⊕(arg) {
|
||||
self + arg
|
||||
}
|
||||
}
|
||||
|
||||
say (21 ⊕ 42)
|
||||
20
Task/Metaprogramming/Sidef/metaprogramming-2.sidef
Normal file
20
Task/Metaprogramming/Sidef/metaprogramming-2.sidef
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
var colors = Hash(
|
||||
'black' => "000",
|
||||
'red' => "f00",
|
||||
'green' => "0f0",
|
||||
'yellow' => "ff0",
|
||||
'blue' => "00f",
|
||||
'magenta' => "f0f",
|
||||
'cyan' => "0ff",
|
||||
'white' => "fff",
|
||||
)
|
||||
|
||||
colors.each { |color, code|
|
||||
String.def_method("in_#{color}", func (self) {
|
||||
'<span style="color: #' + code + '">' + self + '</span>'
|
||||
})
|
||||
}
|
||||
|
||||
say "blue".in_blue;
|
||||
say "red".in_red;
|
||||
say "white".in_white;
|
||||
Loading…
Add table
Add a link
Reference in a new issue