Fantom Puzzlers
Here are 6 simple but slightly tricky Fantom questions. For each program
on the left select the answer on the right and click next. Try these
without actually executing the code :). Safely assume that
- Logging at all levels is on for every problem.
- Logging prints just what’s passed and does not print anything else
like current time, level etc
Excellent, You got 3 out of 6 right
Question 1 : Grandpa's ghost
class Parent : GrandParent{
Void main(){
g := GrandParent.make
g.run
}
}
class GrandParent{
new make(){
echo("A Grand parent is made")
}
Void run(){
echo("zzzz")
}
}
→
Question 2 : Longer the arrow, Easier it is to hit
class Arrow{
Log log := Log.get("arrow")
Void main(){
toStr := 3
echo(toStr.toStr)
echo(toStr -> toStr)
echo(toStr --> toStr)
}
}
→
Question 3 : The Nasty Actor
using concurrent
class LogTheError{
Log log := Log.get("something")
Void main(){
a := Actor(ActorPool())|msg|{
try{
log.info("called with $msg")
return msg.toStr
}
catch(Err e){
log.err("something bad", e)
return "error"
}
}
log.info(a.send(2).get)
}
}
→
Question 4 : A Broken Calculator
class Calculator{
Int a := 0
Int b := 0
override Str toStr(){
return "" + (a+b)
}
}
class TestCalculator{
Void main(){
c := Calculator{a := 10}
echo(c)
}
}
→
Question 5 : The magic of FFI
using [java]java.lang::String as JString
class FFI{
Void main(){
obj := JString("test")
Obj char := obj->charAt(0)
echo(char.typeof)
}
}
→
Question 6 : The case of broken unicode
class Unicode{
Void main(){
a := Str["2","\u0001", "3"]
for(i:=0;i<a.size; i++){
switch(a[i]){
case "2":
echo("2")
break
case "3":
echo("3")
break
default:
echo("UNICODE, I HATE YOU")
break
}
}
}
}
→
Post by Kaushik Sathupadi, Founder
Cull.io - A platform to recruit web developers by having them develop a web application