Erlang (programming language)/Tutorials/Command Line: Difference between revisions
imported>Eric Evers No edit summary |
imported>Meg Taylor m (spelling: differnce -> difference) |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
Getting to know the erlang command line. | {{subpages}} | ||
==Getting to know the erlang command line.== | |||
===Talk to the command line=== | |||
Erlang has a command line like lisp, python and prolog. | Erlang has a command line like lisp, python and prolog. | ||
Line 5: | Line 8: | ||
unless you force it to forget with f(). f() makes it forget | unless you force it to forget with f(). f() makes it forget | ||
all variables. Let us do some simple list manipulations | all variables. Let us do some simple list manipulations | ||
at the command line with head, hd(), | at the command line with | ||
head, hd(), | |||
tail, tl(), | |||
list difference, --, and | |||
list sum, ++. | |||
[reason7@localhost ~]$ erl | [reason7@localhost ~]$ erl | ||
1> L = [b,c,d,5]. | 1> L = [b,c,d,5]. | ||
[b,c,d,5] | [b,c,d,5] | ||
2> hd(L) | 2> hd(L). | ||
b | |||
3> H = [f,t]. | 3> H = [f,t]. | ||
Line 33: | Line 40: | ||
1) Assume 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/why not? Does there exist any list whose tail is equal to its head? | ||
Why/why not? | |||
2) Is the length of A++B always longer | |||
2) Is the length of A++B always longer than either A or B? | |||
Can you give a counter example? | 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? | Can you give a counter example? | ||
===Command line handy tricks=== | |||
If you type a package name with a colon, then hit tab, you see all the functions it owns. | |||
lists: <tab> | |||
gives: | |||
ll/2 all/3 any/2 any/3 | |||
append/2 concat/1 delete/2 dropwhile/2 | |||
filter/2 filter/3 flat_length/1 flatlength/1 | |||
... |
Latest revision as of 00:16, 7 February 2010
The metadata subpage is missing. You can start it via filling in this form or by following the instructions that come up after clicking on the [show] link to the right. | |||
---|---|---|---|
|
Getting to know the erlang command line.
Talk to the 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(), tail, tl(), list difference, --, and list sum, ++.
[reason7@localhost ~]$ erl
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/why not? Does there exist any list whose tail is equal to its head? Why/why not?
2) Is the length of A++B always longer than 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?
Command line handy tricks
If you type a package name with a colon, then hit tab, you see all the functions it owns.
lists: <tab>
gives:
ll/2 all/3 any/2 any/3 append/2 concat/1 delete/2 dropwhile/2 filter/2 filter/3 flat_length/1 flatlength/1 ...