Erlang (programming language)/Tutorials/Command Line: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Eric Evers
(New page: Getting to know the erlang command line. Erlang has a command line like lisp, python and prolog. In the erlang command line you may not reuse a variable, unless you force it to forget wi...)
 
imported>Eric Evers
No edit summary
Line 32: Line 32:
Questions:
Questions:


1) If Q=[[a,b],[a,b]] is the head of Q equal to the tail of Q?
1) Assume Q=[[a,b],[a,b]]. Is the head of Q equal to the tail of Q?
why?
Why?


2) Is the length of A++B always longer the either A or B?
2) Is the length of A++B always longer the either A or B?
Can you give a counter example?


3) Is the lenght of A--B always shorter than A?
3) Is the lenght of A--B always shorter than A?
Can you give a counter example?

Revision as of 12:34, 27 August 2008

Getting to know the erlang command line.

Erlang has a command line like lisp, python and prolog. In the erlang command line you may not reuse a variable, unless you force it to forget with f(). f() makes it forget all variables. Let us do some simple list manipulations at the command line with head, hd(), and tail, tl().

[reason7@localhost ~]$ erl
Eshell V5.5  (abort with ^G)
1> L = [b,c,d,5].
[b,c,d,5]
2> hd(L) = b
3> H = [f,t].
[f,t]
4> H++L.
[f,t,b,c,d,5]
5> Q = [[a,b],[a,b]].
[[a,b],[a,b]]
6> hd(Q).
[a,b]
7> tl(Q).
[ [a,b ] ]

Questions:

1) Assume Q=[[a,b],[a,b]]. Is the head of Q equal to the tail of Q? Why?

2) Is the length of A++B always longer the either A or B? Can you give a counter example?

3) Is the lenght of A--B always shorter than A? Can you give a counter example?