Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #5099
| From | Tarkin <Tarkin000@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Yay! CGI forth interpreter success |
| Date | 2011-08-20 23:07 +0000 |
| Organization | SGMTech |
| Message-ID | <Xns9F47C275BCF46Tarkin000gmail.com@88.198.244.100> (permalink) |
| References | (3 earlier) <7c96f59e-552b-43c9-9797-b8924daa2d41@o20g2000yqo.googlegroups.com> <Xns9F37C2583B515Tarkin000gmail.com@88.198.244.100> <dd6cdcb8-c318-44ed-bbda-471e4dbdb99b@j1g2000yqn.googlegroups.com> <Xns9F40E1D745531Tarkin000gmail.com@88.198.244.100> <11fabd8e-7a73-4e57-8e1d-b76d983b73fe@a17g2000yqk.googlegroups.com> |
John Passaniti <john.passaniti@gmail.com> wrote in news:11fabd8e-7a73-
4e57-8e1d-b76d983b73fe@a17g2000yqk.googlegroups.com:
> On Aug 13, 10:12 pm, Tarkin <Tarkin...@gmail.com> wrote:
>> Simple enough (aside from typecasting)?
>
> Completely unnecessary typecasting; every last one of them can be
> removed. And you should probably read up on the array/pointer duality
> of C so you avoid putting a redundant "&" in front of "object". And
Yes. D'oh!
> the final call to printf doesn't have a format string so it will fail
> if the string you're generating has a format specifier in it.
>
Yes, but besides being crappy code, it was a contrived example, and the
data 'never' would have a format specifier. I see your point, however,
because oddities can,will, and do creep in.
>> So, in flow-Forth:
>> [...]
>> JSON S" { " STR+
>>
>> JSON S" result: " STR+
>> JSON Q" OK" STR+
>>
>> JSON S" , data:" STR+
>> JSON Q" FORTH" STR+
>> JSON S" }" STR+
>>
>> JSON .STR
>
> This roughly matches the C code you wrote. And like the C code,
> you're spending your time concatenating bits of strings together. The
> result is that anyone looking at the C or Forth code has to piece
> together the string fragments to figure out what the output will be.
> But what if you started with this functionally-equivalent C code:
>
> #include <stdio.h>
>
> int main(int argc, char **argv) {
> printf(
> "{ result:'%s', data:'%s' }",
> argc > 1 ? "OK" : "FAIL",
> argc > 1 ? argv[1] : ""
> );
> return 0;
> }
>
> Here, the format string tells you exactly what is being generated by
> showing a template. So that suggests one approach for the Forth
> version-- you could come up with template system where some escape
> either references a quantity on the stack or a named value found in
> the dictionary. I'm not suggesting replicating printf in Forth;
> although printf has it's charms, there are better models for
> interpolating values in string templates, especially for languages
> (like Forth) where you can look up variables by name at run-time.
>
Oh I agree. printf is very much a blast from the past of C.
>> By dealing with XML, one could encapsulate a lot of web-programming:
>> server-side - XHTML generation, SOAP, XML-RPC, etc
>> client-side - XMLHTTP
>>
>> While I am hard pressed to think of a 'modern' browser that won't
>> handle JSON (if JS is enabled, that is), XML is ubiquitous.
>
> Outside of the Forth world, you just build up whatever data structure
> you need, and then serialize it as JSON, XML, YAML, some binary form,
> or whatever makes sense. And since you haven't coupled together the
> data with routines to serialize it, you are free to change it over
> time or support multiple formats.
>
> XML is ubiquitous, but before you can use XML-encoded data, you have
> to deserialize it and then create the appropriate data structures.
> With JSON, the representation *is* the same data structure.
>
A pro for JSON, and con for XML, although in the Spidermonkey
standalone/embeddable JS interpreter, there is an extension called
E4X where XML objects are as flexible as JSON.
TTFN,
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Yay! CGI forth interpreter success Tarkin <tarkin000@gmail.com> - 2011-07-24 19:08 -0700
Re: Yay! CGI forth interpreter success Mark Wills <forthfreak@forthfiles.net> - 2011-07-25 05:17 -0700
Re: Yay! CGI forth interpreter success John Passaniti <john.passaniti@gmail.com> - 2011-07-25 18:31 -0700
Re: Yay! CGI forth interpreter success BruceMcF <agila61@netscape.net> - 2011-07-25 22:53 -0700
Re: Yay! CGI forth interpreter success Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-07-26 19:34 +0000
Re: Yay! CGI forth interpreter success Paul Rubin <no.email@nospam.invalid> - 2011-07-26 01:21 -0700
Re: Yay! CGI forth interpreter success Mark Wills <forthfreak@forthfiles.net> - 2011-07-26 01:57 -0700
Re: Yay! CGI forth interpreter success Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-07-26 19:48 +0000
Re: Yay! CGI forth interpreter success mhx@iae.nl (Marcel Hendrix) - 2011-07-27 21:33 +0200
Re: Yay! CGI forth interpreter success crc <charles.childers@gmail.com> - 2011-07-29 13:10 -0700
Re: Yay! CGI forth interpreter success Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-07-26 17:48 +0100
Re: Yay! CGI forth interpreter success Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-07-26 17:54 +0100
Re: Yay! CGI forth interpreter success crc <charles.childers@gmail.com> - 2011-07-26 12:02 -0700
Re: Yay! CGI forth interpreter success Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-07-29 17:36 +0100
Re: Yay! CGI forth interpreter success anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-07-26 17:06 +0000
Re: Yay! CGI forth interpreter success Tarkin <tarkin000@gmail.com> - 2011-07-30 12:35 -0700
Re: Yay! CGI forth interpreter success Julian Fondren <ayrnieu@gmail.com> - 2011-07-30 16:03 -0500
Re: Yay! CGI forth interpreter success Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-07-31 10:47 +0000
Re: Yay! CGI forth interpreter success Tarkin <tarkin000@gmail.com> - 2011-07-31 11:11 -0700
Re: Yay! CGI forth interpreter success John Passaniti <john.passaniti@gmail.com> - 2011-08-03 09:41 -0700
Re: Yay! CGI forth interpreter success Spam@ControlQ.com - 2011-08-03 13:54 -0400
Re: Yay! CGI forth interpreter success Tarkin <Tarkin000@invalid.com> - 2011-08-04 23:06 +0000
Re: Yay! CGI forth interpreter success John Passaniti <john.passaniti@gmail.com> - 2011-08-11 16:48 -0700
Re: Yay! CGI forth interpreter success Tarkin <Tarkin000@gmail.com> - 2011-08-14 02:12 +0000
Re: Yay! CGI forth interpreter success John Passaniti <john.passaniti@gmail.com> - 2011-08-13 22:03 -0700
Re: Yay! CGI forth interpreter success Tarkin <Tarkin000@gmail.com> - 2011-08-20 23:07 +0000
Re: Yay! CGI forth interpreter success Tarkin <tarkin000@gmail.com> - 2011-07-31 11:12 -0700
Re: Yay! CGI forth interpreter success Tarkin <tarkin000@gmail.com> - 2011-07-31 11:24 -0700
csiph-web