This world allows you to experiment with the recursive strings, as
they were first defined in Lisp. It is very similar to the BatWorld,
but you are supposed to write recursive functions working on
[!python|java]recursive strings. Since [!thelang] does not provide
such a construct natively, the ConsWorld defines recursive lists of
type RecList
.[/!]
[!scala]lists of integers (List[Int]
).
Any given such list is either the empty list
(noted [!scala]Nil[/!][!java]null[/!][!python]None[/!]
),
or an integer followed by a list. If a list is not empty, you can
retrieve its first integer with list.head
and the list
containing its other parameters with list.tail
. Of
course, the empty list has no head nor the tail, so trying to access
these elements will result in an (unpleasant) error message.
To build your own list, you need to concatenate a head and a tail
as follows:
[!java|python]cons(head, tail)
[/!]
[!scala]head::tail
Note that ::
is a generic
operator in Scala to build lists.[/!]
So, in summary, you can solve every exercises of this lesson with the following constructs.
[!java]null[/!][!scala]Nil[/!][!python]None[/!]
l
l.head
l.tail
value
and a list
:
[!java|python]cons(value, list)[/!] [!scala]
value::list[/!]