Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Don Y <this@isnotme.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: things i would ban from clc |
| Date | 2012-03-14 12:41 -0700 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <jjqs8d$e4o$1@speranza.aioe.org> (permalink) |
| References | (17 earlier) <4F5FB8C6.6030308@verizon.net> <jjoeic$nvu$1@speranza.aioe.org> <4F5FC58A.9040909@verizon.net> <jjojtk$5ps$1@speranza.aioe.org> <4f604550$0$1385$4fafbaef@reader2.news.tin.it> |
On 3/14/2012 12:18 AM, io_x wrote:
> i see above as:
>
> #define R return
> #define G goto
> #define u8 unsigned char
> #define u32 unsigned
>
> // at end of progr someone has to free the list children
> i32 greetings(
> u8 *output, # communication channel named "output"
No. The *data type* of "output" is "communication channel".
There is no counterpart in C. Think of it as a "named pipe"
that connects two threads -- possibly across machine boundaries.
You could provide similar functionality with a *socket*, a FIFO
or a managed shared memory region (in some contexts). But, you
would have to explicitly set up this mechanism (function calls).
Limbo lets you just create one (and "pass it around") just like
you would an int, etc.
So, while you can accumulate the stuff intended to be transfered
across that channel *in* a string (assuming the channel is
declared to support strings -- and not ints or some other
data type!), you still have to actively *pass* it across
some communication mechanism.
Threading implies communication between threads. Channels
formalize that.
> u8 *surname, # parameter of type "string"
> u8 *children # a list of tuples each
Not sure how you plan on storing those, yet... Note that Limbo
makes it clear what you are intending *in* the declaration:
"This is a LIST of TUPLES where each is tuple consists of
a string (the child's name) and an integer (his age)"
> ) {u8 *tmpStr, *tmpPlist;
> i32 r=0;
> if(surname==0||output==0||children==0||ListNotOk(children))
> R 1;
>
> # create a string by concatenating the two string constants
> # with the string *variable* passed to the function as "surname"
> # pass the resulting string out the channel named "output"
> # output<-= "Season's Greetings from the "
> # + surname + " family!\n";
>
> // StrMultiCat(u8** , ...) where ... are C string u8*
> if( StrMultiCat(&tmpStr, "Season's Greetings from the ",
> surname, " family!\n" )==-1 )
> {err:
> StrDel(&tmpStr); R r
> }
Notice that you have to explicitly manage memory (to avoid leaks).
Limbo ensures that the resources you hold are automatically
free-d when you terminate. I.e., it is part of the *language*
specification, not the "hosting environment".
> if( StrSPut(output, tmpStr) == -1) {r=5; G err;}
Again, all you have done is built a string. No one else
can *see* it! You haven't, yet:
# pass the resulting string out the channel named "output"
> # as long as the "children" list is not empty...
> tmpPlist=0;
> // NextListElement of 0 is the first element of the list
> // [or 0 if it is a void list]
> // NextListElement of the last element of list is 0
> while(NextListElement(&tmpPlist, children)) != 0 ) {
> # extract one the first ("head") element from the "children"
> # list assigning it's component values to "firstname" and "int"
> # the presence of the ':' is a syntactic shortcut that allows
> # the declaration of these variables to be deduced from the
> # values assigned to them (i.e., we know children consists
> # of (string, int) tuples so we know "firstname" is now declared
> # as a string and "age" is an int. I.e., this just saves two
> # lines declaring those types as
> # firstname: string;
> # age: int;
> // firstname: u8* string
> // age: u32
> #(firstname, age) := hd children;
>
> // this assign each list element, the name of children of age hd
> // what is hd? or what is age?
hd = "head"
# extract one the first ("head") element from the "children"
# list assigning it's component values to "firstname" and "int"
My apologies for the typos. This should have said:
# extract one element -- the *first* ("head") element -- from the
# "children"
# list assigning it's component values to "firstname" and "AGE"
I'd have thought the intent would have been obvious even if the
commentary was crap :>
> if( StrMove(tmpPlist, children)==-1 ) {r=6; G err;}
> *(u32*)(tmpPlist+4)=hd;
>
> # ':' tells you that description is of the same type as the
> # rvalue -- a string (since the expression on the right is
> # recognizable as a string). Set the description string
> # variable to the concatenation of the "firstname" and "surname"
> # strings -- with a constant string (whitespace) in the middle
> #description := firstname + " " + surname;
> if( StrMultiCat(&tmpStr, firstname, " ", surname)==-1 )
> {r=7; G err;}
>
> # tack on the parenthetical comment indicating the child's age
> # note the use of '=' instead of ":=" -- since we have already
> # declared description's type
> #description = description
> # + " (" + age + " years old)";
> // you not say what the age is...
See above comment. (firstname, age) can be though of as
struct {
char *firstname;
int age;
}
The "children" list could be implemented as either a linked list
of these structs *or* an array -- with suitable code wrapped
around it to allow it to grow and shrink as needed.
> if( StrCat(&tmpStr, " (") == -1 ){r=10; G err;}
> if( StrCat_u32(&tmpStr, age) == -1 ){r=11; G err;}
> if( StrCat(&tmpStr, " years old)") == -1 )
> {r=12; G err;}
>
> # pass the "fullname" (grrr... should have been "description")
> # string to the communication channel named "output"
> # output<-= fullname;
>
> if( StrSPut(output, tmpStr) == -1 ) {r=13; G err;}
>
> # assign the balance (everything beyond the "head") of the children
> # list to the children list variable
>
> # children = tl children;
> not traslated: what is t1?
tl == "tail"
# assign the balance (everything beyond the "head") of the children
-------------^^^^^^^^^^^---^^^^^^^^^^^^^^^^^^^^^^^^^^
# list to the children list variable
> }
> StrDel(&tmpStr);
> R r;
> }
Notice how much "manual" work you have to do to implement the
same sorts of functionality? More opportunities for mistakes
(did you remember to free all your resources regardless of
the path you took through the code, etc.). Limbo's syntax
is a lot cleaner (though admittedly cryptic for novices)
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
things i would ban from clc jgk@panix.com (Joe keane) - 2012-03-11 23:05 +0000
Re: things i would ban from clc Keith Thompson <kst-u@mib.org> - 2012-03-12 10:33 -0700
Re: things i would ban from clc gazelle@shell.xmission.com (Kenny McCormack) - 2012-03-12 23:57 +0000
Re: things i would ban from clc jacob navia <jacob@spamsink.net> - 2012-03-12 18:44 +0100
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-12 12:26 -0700
Re: things i would ban from clc "osmium" <r124c4u102@comcast.net> - 2012-03-12 14:36 -0600
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-12 13:57 -0700
Re: things i would ban from clc James Kuyper <jameskuyper@verizon.net> - 2012-03-12 17:34 -0400
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-12 15:00 -0700
Re: things i would ban from clc James Kuyper <jameskuyper@verizon.net> - 2012-03-12 18:21 -0400
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-12 15:43 -0700
Re: things i would ban from clc jacob navia <jacob@spamsink.net> - 2012-03-12 23:53 +0100
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-12 17:17 -0700
Re: things i would ban from clc jacob navia <jacob@spamsink.net> - 2012-03-13 09:09 +0100
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 01:24 -0700
Re: things i would ban from clc Keith Thompson <kst-u@mib.org> - 2012-03-13 05:59 -0700
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 10:55 -0700
Re: things i would ban from clc blp@cs.stanford.edu (Ben Pfaff) - 2012-03-13 11:07 -0700
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 11:25 -0700
Re: things i would ban from clc blp@cs.stanford.edu (Ben Pfaff) - 2012-03-13 11:32 -0700
Re: things i would ban from clc Keith Thompson <kst-u@mib.org> - 2012-03-13 12:18 -0700
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 16:13 -0700
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 13:49 -0700
Re: things i would ban from clc James Kuyper <jameskuyper@verizon.net> - 2012-03-13 17:14 -0400
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 14:35 -0700
Re: things i would ban from clc James Kuyper <jameskuyper@verizon.net> - 2012-03-13 18:09 -0400
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 16:06 -0700
Re: things i would ban from clc "io_x" <a@b.c.invalid> - 2012-03-14 08:18 +0100
Re: things i would ban from clc "io_x" <a@b.c.invalid> - 2012-03-14 10:07 +0100
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-14 12:41 -0700
Re: things i would ban from clc "io_x" <a@b.c.invalid> - 2012-03-14 21:53 +0100
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-15 14:16 -0700
Re: things i would ban from clc "io_x" <a@b.c.invalid> - 2012-03-18 07:14 +0100
Re: things i would ban from clc Jens Gustedt <jens.gustedt@loria.fr> - 2012-03-14 10:39 +0100
Re: things i would ban from clc Ben Pfaff <blp@cs.stanford.edu> - 2012-03-13 14:33 -0700
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 14:40 -0700
Re: things i would ban from clc Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-13 16:25 -0700
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-14 00:51 -0700
Re: things i would ban from clc Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-14 14:25 -0700
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-15 13:40 -0700
Re: things i would ban from clc Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-18 17:05 -0700
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-23 11:59 -0700
Re: things i would ban from clc Robert Wessel <robertwessel2@yahoo.com> - 2012-03-23 17:02 -0500
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-23 16:51 -0700
Re: things i would ban from clc "io_x" <a@b.c.invalid> - 2012-03-24 07:16 +0100
Re: things i would ban from clc Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-27 11:26 -0700
Re: things i would ban from clc Kaz Kylheku <kaz@kylheku.com> - 2012-03-23 19:43 +0000
Re: things i would ban from clc Rui Maciel <rui.maciel@gmail.com> - 2012-03-23 19:45 +0000
Re: things i would ban from clc Jens Gustedt <jens.gustedt@loria.fr> - 2012-03-23 23:49 +0100
Re: things i would ban from clc Ian Collins <ian-news@hotmail.com> - 2012-03-24 11:54 +1300
Re: things i would ban from clc Jens Gustedt <jens.gustedt@loria.fr> - 2012-03-24 09:26 +0100
Re: things i would ban from clc gwowen <gwowen@gmail.com> - 2012-03-26 07:31 -0700
Re: things i would ban from clc Kaz Kylheku <kaz@kylheku.com> - 2012-03-24 05:45 +0000
Re: things i would ban from clc Jens Gustedt <jens.gustedt@loria.fr> - 2012-03-24 09:31 +0100
Re: things i would ban from clc James Kuyper <jameskuyper@verizon.net> - 2012-03-13 14:34 -0400
Re: things i would ban from clc Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-13 16:18 -0700
Re: things i would ban from clc "io_x" <a@b.c.invalid> - 2012-03-14 08:18 +0100
Re: things i would ban from clc Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-14 14:06 -0700
Re: things i would ban from clc Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-03-15 15:22 +0000
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-15 12:26 -0700
Re: things i would ban from clc jacob navia <jacob@spamsink.net> - 2012-03-15 21:28 +0100
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-15 13:49 -0700
Re: things i would ban from clc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-15 16:36 +0000
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-15 12:16 -0700
Re: things i would ban from clc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-16 00:13 +0000
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-15 20:40 -0700
Re: things i would ban from clc gwowen <gwowen@gmail.com> - 2012-03-13 01:52 -0700
Re: things i would ban from clc "io_x" <a@b.c.invalid> - 2012-03-13 11:31 +0100
Re: things i would ban from clc jacob navia <jacob@spamsink.net> - 2012-03-13 11:41 +0100
Re: things i would ban from clc gwowen <gwowen@gmail.com> - 2012-03-13 06:06 -0700
Re: things i would ban from clc jacob navia <jacob@spamsink.net> - 2012-03-13 15:06 +0100
Re: things i would ban from clc ImpalerCore <jadill33@gmail.com> - 2012-03-13 07:46 -0700
Re: things i would ban from clc jacob navia <jacob@spamsink.net> - 2012-03-13 19:08 +0100
Re: things i would ban from clc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-13 13:20 +0000
Re: things i would ban from clc Jens Gustedt <jens.gustedt@loria.fr> - 2012-03-13 20:41 +0100
Re: things i would ban from clc Kaz Kylheku <kaz@kylheku.com> - 2012-03-13 19:34 +0000
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 16:14 -0700
Re: things i would ban from clc Kaz Kylheku <kaz@kylheku.com> - 2012-03-13 23:28 +0000
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 21:18 -0700
Re: things i would ban from clc Ian Collins <ian-news@hotmail.com> - 2012-03-13 20:19 +1300
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-13 01:09 -0700
Re: things i would ban from clc Ian Collins <ian-news@hotmail.com> - 2012-03-13 21:32 +1300
Re: things i would ban from clc nick_keighley_nospam@hotmail.com - 2012-03-13 01:52 -0700
Re: things i would ban from clc "io_x" <a@b.c.invalid> - 2012-03-13 11:31 +0100
Re: things i would ban from clc nick_keighley_nospam@hotmail.com - 2012-03-14 01:18 -0700
Re: things i would ban from clc Don Y <this@isnotme.com> - 2012-03-14 12:09 -0700
Re: things i would ban from clc ArifulHossain tuhin <etothepowerpi@gmail.com> - 2012-03-14 13:01 -0700
csiph-web