
Both mother and baby are doing well...
The often deranged postings of yet another hacker, pretending to be an Astronomer, pretending to be a hacker who has written a book or two for O'Reilly Media.
1> A = 123.
123
2> A.
123
3> A = 124.
** exception error no match of right hand
4> f().
ok
5> A = 124.
124
area( {square, Side} ) ->
Side * Side ;
area( {circle, Radius } ) ->
3.14 * Radius * Radius;
area( {triangle, A, B, C} ) ->
S = ( A + B + C )/2,
math:sqrt(S*(S-A)*(S-B)*(S-C));
area( Other ) ->
{error, invalid_object}.
;
'. Erlang programs consist of a collection of modules that contain functions that call each other. Function and modules names must be atoms.factorial(0) ->
1;
factorial(N) ->
N * factorial(N-1).
.erl
suffix, module and file names must be the same. Modules are names with the -module(Name).
directive.-module(demo).
-export([double/1]).
% Exporting the function double with arity 1
double(X) ->
times(X, 2).
times( X, N ) ->
X * N.
1> cd("/Users/aa/").
2> c(demo).
{ok,demo}
3> demo:double(10).
20
4> demo:times(1,2)
**exception error: undefined function demo:times
case lists:members(foo, List) of
true -> ok;
false -> {error, unknown}
end
_
' or an unbound variable in the last clause to ensure this happens.if
X < 1 -> smaller;
X > 1 -> greater ;
X == 1 -> equal
end
true
as the last guard you ensure that the last clause will always succeed should previous ones evaluate to false, see it as an 'else' clause. So we can have,factorial(N) when N > 0 ->
N * factorial( N - 1 );
factorial(0) ->
1.
factorial(0) ->
1;
factorial(N) ->
N * factorial(N-1).
,
' to seperate them, if one has to succeed, use ';
' to separate them. Guards have to be free of side effects.average(X) -> sum(X) / len (X).
sum([H|T) -> H + sum(T);
sum([]) -> 0.
len([_|T]) -> 1 + len(T);
len([]) -> 0.
date()
time()
length(List)
size(Tuple)
atom_to_list(Atom)
list_to_tuple(List)
integer_to_list(234)
tuple_to_list(Tuple)
Pid2 = spawn(Mod, Func, Args)
recieve
{resetn, Board } -> reset(Board);
{shut_down, Board{ -> {error, unknown_msg}
end
case
block, receive suspends the process until a message which matches a case is received. Message passing is asynchronous, one of the things you look for in stress testing Erlang systems is running out of memory because of full mailboxes.You have to minimise wear and tear on all parts of the keyboard
Far too few people are using their source code as their user interface
Our company was built in 3 hours, the rest was marketing bullshit - Bill Gates
Amazing product are never built in a long time. Just short, simple acid trips - Steve Jobs
The Django guys will say 'Don't say it's like rails,' but it is like rails.Which reminds me, I must take a serious look at Catalyst at some point...
If you can't make it good, at least make it look good - Bill Gates
Intellectual property has the shelf life of a banana - Bill Gates
autodie
module, which was released onto CPAN (very) late last night. It's a lexical equivalent of Fatal
for Perl 5.10, it also upgrades the Fatal
module to contain better diagnostics and reporting.-t
...You may not use data derived from outside your program to affect something else outside your program - at least, not by accident. - perlsec
PERL5LIB
environment variable.If the regular expression match formy ($url, $file) = @ARGV;
$url =~ m/ pattern match /;
my $safe_url - $1;
$file =~ / pattern match /;
my $safe_file = $1;
$safe_file
fails then $safe_file
is set to $safe_url
and that could easily be set to something like http://foo&/bin/sh
, which would be bad. You always need to check for success, either use an if( )
block or by explicitly check the return value from the regular expression.open
which does much deep magic. Use the three argument version instead.However this doesn't get you out of validating your input, you still need to do that...open($fh, "<", $filename );
use autodie qw(open);
open($fh, "+>", undef );
File::Temp
module instead...system
and back ticks, Paul really hates system
. You really need to use the two argument version of system
rather than the one argument version, except of course@args = ();
system( $cmd, @args );
@args
is empty, then it calls the one argument version of system
, which in turn calls the shell rather than executes the passed command directly. Which means that you can this happens,system ( "finger $username; rm -rf *", ( ) );
IPC::System::Simple
, which works all the way back to Pelr 5.6 and (magically) doesn't have any dependencies. Which from the sounds of it goes a long way to fixing a lot of the problems with system
. It also provides capture
which replaces back ticks.setuid
and setgid
programs. Apparently Perl is ignorant of the saved uid, which means that it's really hard to drop privileges and make it stick. Also a dark secret, Perl's $<
and $>
variables are cached. Ouch!s.lower()
, s.upper()
, s.strip()
and the like. Of course since strings are immutable, they don't do an in place operation.We're talking about a Turing complete language, so there is always more than one way of doing things...when talking about there being only one way of doing things in Python.
print
statement is actually going away in Python 3.0, replaced by the print
function. Which, yes, makes a big difference. That's a subtle but fairly fundamental change. Have to think about that for a bit...def
is an executable statement. The interpreter reads and compiles the indented body and the resulting function object is bound to the function name in current namespace.Some functions can take an indefinite number of positional and keyword arguments. These are caught with a special parameter syntax;which is only sort of like the way Perl does things...*name
becomes a tuple of "extra" positional arguments to a call**name
becomes a dict of "extra" keyword arguments to a call:n=v
becomes{n: v}
$self
when using an instance. That's interesting...Five minutes left to cover formatting and I/O...That's not good. Nor is the fact that it's only in "modern" Python that you can iterate over a file and don't have to read it in all at once. Hmm...
callAndWait( )
functionality, I'll be adding that in this week, but should in all other ways meet the 1.0 WD and be interoperable with the other emerging toolkits. callAndWait( )
, which will be tagged alpha4, this will be the last 'initial' release. After this I'll take some time to clean up the code, add some documentation, and make the client toolkit a bit more pleasant to use before making a 'first' release.XMLRPC::Lite
(part of the SOAP::Lite
module), XML::Simple
, DateTime
, File::Spec
, Carp
, Data::Dumper
, Getopt::Long
, Socket
, Net::Domain
, POSIX
and Errno
. Depending on your version of Perl some, but not all, of these will ship with the core distribution. The rest can be obtained from CPAN. I think I've caught all the dependancies, but if you notice any I haven't listed any let me know I've forgotten them.% tar -zxvf perl-samp-hub-alpha3.tar.gz
% cd perl-samp-hub-alpha3/
% ./samp_hub.pl
% tar -zxvf perl-samp-clients-alpha3.tar.gz
% cd perl-samp-clients-alpha3/
% ./listener_client.pl
notify( )
and call( )
's from the Hub. In the second window you can either start the client that exercises the notify( )
method, or the other than exercises the call( )
method. So% cd perl-samp-clients-alpha3/
% ./callAll_test.pl
% cd perl-samp-clients-alpha3/
% ./notifyAll_test.pl
PAR::Packer
than I am would be warmly welcomed.