Home   Archive   Permalink



CGI web programming supported by REBOL dialect Meta

The Meta language now officially supports web programming through the Common Gateway Interface as a use case.
    
We upgraded Meta and verified that Meta programs run as CGI programs on at least Linux and Windows. They likely also work on other platforms. If not, please report it on the Meta forum:
    
social.metaproject.frl/Meta/
    
Meta supports the most important features needed for writing meaningful CGI programs, such as environment variables and standard input and output in text and binary forms. Arnold van Hofwegen wrote a CGI tutorial:
    
language.metaproject.frl/documentation/

posted by:   Kaj de Vos     26-May-2023/15:47:01-7:00



Is there a version for Linux (to run on Chromebook)?

posted by:   Nick     27-May-2023/17:03:57-7:00



Meta executables for PC are portable. They are able to run on Linux:
    
language.metaproject.frl#get
    
If you have a Chromebook with an ARM processor, you need to install QEmu user-mode emulation.

posted by:   Kaj     27-May-2023/19:15:08-7:00



αcτµαlly pδrταblε εxεcµταblεs are pretty cool! ... and I got sidetracked reading about sectorlisp :)

posted by:   Nick     28-May-2023/18:38:02-7:00



:-)

posted by:   Kaj     29-May-2023/6:27:55-7:00



You may like SectorC.

posted by:   Kaj     2-Jun-2023/6:14:22-7:00



"grammar is 704 bytes in ascii, 38% larger than it's implementation" - that's cool :) Also, although "Move to the South Pole with absolutely no gear on a Homesteading Mission" sounds like awesome fun, but a bit out of my range at the moment ;)

posted by:   Nici     2-Jun-2023/8:12:14-7:00



BTW, I did get Meta running on my Chromebook with Arm processor, using qemu :)

posted by:   Nick     2-Jun-2023/8:25:12-7:00



Great, it would be good to know if this setup also works for CGI programs.
    
Of course, computation speed is a lot slower under emulation, but it will still be a lot faster than REBOL and Red. It would be interesting to test the relative speeds.

posted by:   Kaj     2-Jun-2023/9:37:23-7:00



I compiled the newest version of "Pig Latin example for CGI" (posted in our previous discussion and test on Windows) as program.com, which I placed in ./cgi-bin. When I run ./program.com on the command line, I get the expected result:
    
Content-type: text/plain
    
So I tried running:
    
python3 -m http.server --bind localhost --cgi 8080
    
When I do this in the browser:
    
http://localhost:8080/cgi-bin/program.com?a=this%20is%20cool
    
I don't get any error, or any output displayed in the browser. This is the response on the command line:
    
Serving HTTP on ::1 port 8080 (http://[::1]:8080/) ...
::1 - - [02/Jun/2023 10:14:20] "GET /cgi-bin/program.com?a=this%20is%20cool HTTP/1.1" 200 -
http://localhost:8080/cgi-bin/program.com?a=this%20is%20cool
    
So decent news (no errors). I don't currently have any other generic web server currently set up on my Chromebook, and expect the reason for no displayed results in the browser window.
    
I also tried:
    
curl http://localhost:8080/cgi-bin/program.com?a=this%20is%20cool
    
and got no printed response at the command line (but also no error)
    
I'd have to look into another server for Chromebook to do any more testing...

posted by:   Nick     2-Jun-2023/10:19:42-7:00



I also tested the earlier version of the pig y script, and it also didn't print any CGI output, but also returned a successful 200 response. I can install Apache and try with it, later...

posted by:   Nick     2-Jun-2023/10:45:08-7:00



Actually, I tested that with the incorrect binary. Your original example did compile and run properly as a CGI example!
    
http://localhost:8080/cgi-bin/program2.com?a=this%20is%20cool
    
returns:
    
is%20is%20coolthay
    
Congrats, success with CGI on Chromebook!
    
To be clear, I compiled this code:
    
Meta [
     Title: "Pig Latin example for CGI"
     Author: ["Nick Antonaccio" "Kaj de Vos"]
     Rights: "Copyright (c) 2020-2022 Kaj de Vos"
     License: {
         PD/CC0
         http://creativecommons.org/publicdomain/zero/1.0/
     }
     Purpose: {
         Convert words to Pig Latin through CGI.
     }
     Notes: {
         https://en.wikipedia.org/wiki/Pig_Latin
        
         Ported by Kaj de Vos from the original in REBOL 2 by Nick Antonaccio:
         http://rebolforum.com/index.cgi?f=printtopic&permalink=Nick16-Jun-2022/11:12:40-7:00&archiveflag=new
     }
]
        
write/line {Content-type: text/plain
}
text: find/tail select/case system/environment "QUERY_STRING" "="
        
while (
     if space: find word: text " " [word: copy cut text space]
        
     unless is-empty word [
         write either is-same word vowel:
             any [find word "a" find word "e" find word "i" find word "o" find word "u"]
         [    ; Word starts with vowel
             write word
             "hay"
         ][
             write either vowel [
                 write vowel
                 copy cut word vowel
             ][
                 word
             ]
             "ay"
         ]
     ]
     space
)[
     write " "
     text: next space
]
    
I'm not sure off hand why the newer script didn't return a response, but this code is useful enough as proof of concept :)
    
Also, to be clear, I ran this with:
    
python3 -m http.server --bind localhost --cgi 8080

posted by:   Nick     2-Jun-2023/10:52:32-7:00



Looks like starting the program as CGI is successful, but the environment variables with the query string are not passed to it.
    
That's not entirely surprising, because starting an APE executable, especially through QEmu, is a roundabout way.
    
You could try a POST CGI program, like in Arnold's examples, to see if standard input is passed.

posted by:   Kaj     2-Jun-2023/10:56:24-7:00



Ah, solved already. Very cool!
    
(And I need to enter get-env as CAPTCHA :-)

posted by:   Kaj     2-Jun-2023/10:59:01-7:00



Note the difference in access of environment variables between REBOL and Meta. REBOL only has the series abstraction for its own native data types, so it needs many special functions such as GET-ENV for external data. No improvement over C and most other languages - you have to remember all those functions. Whereas Meta simply uses the series abstraction for external data.

posted by:   Kaj     2-Jun-2023/11:07:18-7:00



I won't have time till after this weekend to look at it more, but curious if you know why the code above worked, but not the updated example?
    
To be clear, this is the code that didn't print a response value:
    
    
Meta [    
        Title: "Pig Latin example for CGI"    
        Author: ["Nick Antonaccio" "Kaj de Vos"]    
        Rights: "Copyright (c) 2020-2022 Kaj de Vos"    
        License: {    
            PD/CC0    
            http://creativecommons.org/publicdomain/zero/1.0/    
        }    
        Purpose: {    
            Convert (space separated, English) words to Pig Latin through CGI.    
        }    
        Notes: {    
            https://en.wikipedia.org/wiki/Pig_Latin    
        
            Ported by Kaj de Vos from the original in REBOL 2 by Nick Antonaccio:    
            https://rebolforum.com/index.cgi?f=printtopic&permalink=Nick16-Jun-2022/11:12:40-7:00&archiveflag=new    
        }    
    ]    
        
    write/line {Content-type: text/plain    
    }    
    text: find/tail select/case system/environment "QUERY_STRING" "="    
        
    while all [text not is-tail text] [    
        text: if space: find word: text "%20" [    
            word: copy cut text space    
            skip space 3    
        ]    
        unless is-empty word [    
            vowel: none    
            character: word    
        
            until any [    
                is-tail character    
                if find "aeiou" copy cut character 1 [vowel: character]    
            ][    
                advance character    
            ]    
            write either is-same word vowel [ ; Word starts with vowel    
                write word    
                "yay" ; way, hay    
            ][    
                write either vowel [    
                    write vowel    
                    copy cut word vowel    
                ][    
                    word    
                ]    
                "ay"    
            ]    
        ]    
        write " "    
    ]

posted by:   Nick     2-Jun-2023/13:26:44-7:00



One thing that strikes me immediately about this test is that the way it was implemented enables easy integration of Meta code in Python web apps that have no other requirement but the Python ecosystem (now *that piques my curiosity) :)

posted by:   Nick     2-Jun-2023/13:31:27-7:00



Yep, there are many ways Meta and Python could be combined in a system. One of the most natural ways is when a system is divided into micro services, and CGI has always done that.
    
Meta is two orders of magnitude faster than Python, so a natural ways is to do performance-sensitive parts in Meta if you already have a Pyhon system. And when you progress to build systems in Meta, you can still use Python parts to access its ecosystem.
    
Same with JavaScript or any other language that has something you want.

posted by:   Kaj     2-Jun-2023/13:45:14-7:00



The last version you posted is my last version. It should work, unless there's a new bug in the program logic. There´s only one small change in code generation that affects it since we tested.
    
Just add some testing code to debug it like normal.

posted by:   Kaj     2-Jun-2023/14:01:31-7:00



There was no error, just no response printed out by the newest version. Not sure how to debug that...

posted by:   Nick     2-Jun-2023/15:09:37-7:00



I'll take another look next week, just happy to see it running on multiple platforms at this point!

posted by:   Nick     2-Jun-2023/15:21:55-7:00



With a CGI that returns plain text, it's very easy to add debugging code: just add some WRITE/LINE methods.

posted by:   Kaj     2-Jun-2023/15:31-7:00



Name:


Message:


Type the reverse of this captcha text: "y a r r a"



Home