Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - unixtechie

#1
Whither newLISP? / Erlang-like OTP in newlisp??
November 17, 2011, 01:48:06 AM
Hello, newlispers. Have a question to you.



I remember how much impressed I was after reading books by Armstrong and some other on the concepts implemented in Erlang. And even more impressive (than pure Erlang) is the idea of OTP, a generic framework for fail-proof distributed computing.



Today with the new messaging capability btw parent and spawned children enabled in newlisp, it seems possible to implement the same OTP logic purely in newlisp.



It's reasonable to take a primitive example - e.g. downloading in parallel from some web-based repository    - and then implement a "generic tcp server" with callbacks, that make it possible to "program linearly" from the parent, then implement "supervisors" which (like the unix inetd) spawn, rip, restart childred which do the actual work (downloading in our example) in parallel.

Then make it the same for spawing local children or starting remote newlisp workers.

At this point I can imagine how the previous could be approached; I'm less sure - but maybe even the on-the-fly code updates might be possible who knows.



Of course, real processes spawned by newlisp will be heavier that pseudo-processes generated by an erlang virtual machine, but still this approach may make full sense, I think.



Would it be worth it to try this example - with the view of creating a more generic framework (a pure newlisp lib file) if it works OK? Would this be interesting?
#2
I posted this first as a response in a previous post by Kazimir about some newlisp project at github, but let me repost this question.



So, regarding "projects in newlisp on Github":

Could you please look at http://github.com/unixtechie/Literate-Molly/">http://github.com/unixtechie/Literate-Molly/

This is a perl script for literate programming, which extends it with HTML and Javascript "folding" to help manage programmer's attention span and scale the previously unscalable flat literate source files.



It can be recoded in newlisp to become a totally standalone tool, when turned into a newlisp pseudo-executable, without reliance on any "system instllations" of any other tools, nor a web server.



Give me your opinion, Kazimir and other readers, do you think it's worth it?



Read the "MOLLY.html" file first, it's both an example of the weaver output and a sort of documentation of the script and its usage.
#3
http://www.livejournal.com">http://www.livejournal.com - Livejournal - plays a unique role in Russian-language blogosphere. As compared to large US blog services, where majority of users are teenagers (e.g. the US section of LJ averaged at 19 some time ago), the Russian LJ contains people of all ages and most popular book writers, journalists, even politicians etc. etc. consider it necessary to have presence there: this gives access to widest real audience from all parts of the country and to the immigrant community in one swoop.



Where does newlisp come here? - easy. One of the bloggers used newlisp to do estimations of election vote counts (and being someone with somewhat extremist anti-russian views he, naturally, attempts to interpret a very vague statistic as a "proof" of vote rigging, as his likes are prone to, I'd say).



The interesting part of it is that his _technical_ (i.e. non-political) post on how he constructed a simple web pages crawler which downloads 2 levels of referred pages and then cuts out necessary results to export into a processing app _got 388 responses_ with all kinds of comparisons (to 2 versions of perl scripts, shell, python, and even a version in Haskell) and technical discussion.



His post at

http://fritzmorgen.livejournal.com/248335.html?format=light">http://fritzmorgen.livejournal.com/2483 ... rmat=light">http://fritzmorgen.livejournal.com/248335.html?format=light

describes his crawler in detail, giving a piece of code commented and explained line by line and so providing a sort of intro to newlisp, which stirred a surprising degree of enthusiasm.



This is not the first exposure of newlisp in Russian LiveJournal, but most of the mentioning so far ran into sniggering.

So probably what needs to be done for "spreading the word" is just small concrete snippets of code which are thorougly explained. When people see how well-working and minimalistic solutions can be created, they do not fail to get a favourable view of the language. It's probably the generalizations and talk "about" that mostly repel readers and make them  throw stupido generalities back



The post is in Russian. The complete snippet can be seen here:

http://metasatanism.ru/FILES/Linux/election.lsp">http://metasatanism.ru/FILES/Linux/election.lsp  /* Linux */

http://metasatanism.ru/FILES/election.lsp">http://metasatanism.ru/FILES/election.lsp /* Windows */



Alternatives:

http://hpaste.org/fastcgi/hpaste.fcgi/view?id=11008">http://hpaste.org/fastcgi/hpaste.fcgi/view?id=11008  /* haskell */

http://vozutat.livejournal.com/11098.html">http://vozutat.livejournal.com/11098.html /* python */

http://what-me.livejournal.com/6815.html">http://what-me.livejournal.com/6815.html   /* a sort of perl */

http://nponeccop.livejournal.com/152013.html?thread=776141&format=light#t776141">http://nponeccop.livejournal.com/152013 ... ht#t776141">http://nponeccop.livejournal.com/152013.html?thread=776141&format=light#t776141 /* Haskell and Bash in the comment below */
#4
Whither newLISP? / C from newlisp?
October 07, 2009, 03:02:15 AM
I saw some quoted discussion in Kazimir's blog, and there's something maybe relevant to the wider topic of how to use C from scripting languages in general, including newlisp.



There is an excellent open-source project called "tcc", a tiny C compiler. The binary is slightly over 100k (123 on my platform).

It understands all of ANSI C plus some extensions; it can compile libraries or standalone execs, and it can be used for "scripting", if the first line in the file is

a shebang invocation of #!/path/to/tcc (plus some options, e.g. lib includes etc)

TCC also contains an assembler.



The main point is that it runs roughly an order of magnitude faster that GCC (the ratio was 9 in test-compilation of the source of a links web browser, if I am not mistaken).



It also compiles on Windows, i.e. it's crossplatform



HOME PAGE: http://bellard.org/tcc/">http://bellard.org/tcc/



--------------

THEREFORE there are basically several options if one wants to use C or even assembler from his scripting language.



(a) write your C, then invoke "tcc - run" piping output back into your script.

"tcc -run ......" will compile it on the fly and not create an "a.out".

Alternatively, use a simple wrapper that checks if your inline was compiled already and reuses the generated binary, saved as a small file, not to repeat it in subsequent runs.



(b) write your C, then compile it with tcc as a library; use newlisp built-in fuction to load the tiny lib you created on the fly and talk with it using newlisp facilities



(c) TCC itself can be compiled as a static libtcc.a

Its APIs are outlined in its header file. It is possible, generally speaking, to produce an extended version of newlisp with this lib compiled in (just the way a library that implements httpd or some hashing is compiled into it).

I do not believe it is the best way, though, because of the need to learn a whole bunch of API functions and because, while not fattening the newlisp binary that much, such an add-on would prevent newlisp from remaining a standalone exec, as it will tie it to some other files (e.g. headers ), i.e. will require a "system installation". This lack of dependencies is one feature that makes newlisp drastically different (and better than) most scripting languages, in my view.



The amount of wrapping of the C code to be used with such a tiny fast one-the-fly compiler should be negligible, and I would say in most cases of practical use the need to run an extra process for the C sections will not affect the usability of the script.



Two more major points:

- tcc is so small, it generates straightforward stuff in microseconds (5-8 microseconds for something like the Fibonacci test prog). One CAN use that for DYNAMIC generation of C code from your script, not only for pre-compilation of some static parts of a program

- tcc can help in using external libraries which are difficult to use from newlisp itself, directly. One can write a simple wrapper in a few lines which will present the result of an invocation of library functions in the form convenient for passing over to newlisp (e.g. as a string or some list, whatever).





----

There is another project (I'll check the name and add it), which fakes the same scripting approach. The "script" in C is in fact passed to the full GCC compiler on the first invocation, and the compiled a.out is called on subsequent ones.

This of course is (a) slower) and (b) much heavier on IO at least.



So  I believe the TCC road - using a blazingly fast C compiler which can of course link with any existing libraries in C etc. etc. - to write convenient wrappers whenever newlisp operators are at an end and/or to write pseudo-inlined sections of code in C or assembler, which then can be used from the scripting language -- is practical and will cover most of the real-life uses.



-----

P.S. Python people already went that way, as a matter of fact:

http://www.cs.tut.fi/~ask/cinpy/">http://www.cs.tut.fi/~ask/cinpy/

"Cinpy is a Python library that allows you to implement functions with C in Python modules. The functions are compiled with tcc (Tiny C Compiler) in runtime. The results are made callable in Python through the ctypes library."
#5
Programming language operators  are as a rule  very inconsistent. Some return meaningful values, others exist for "side effects", some are greedy, others are lazy or can be made lazy etc. etc.



Functionally aware languages,. such as lisps and newlisp in particular are great, they have nice uniformity.



However there is one task I do not seem to be able to solve easily. This is lazy iteration over strings



That is, I want for a great number of tasks to have ability to do with strings in memory exactly the same thing I can do with newlisp "search" and files: that is lazy processing.

Search gives me some result and advances the offset in the file (which I can read and use later, if I need it). The next invocation of the same search, say in a loop, will give me the second match and I can pick its offset.

The file can be arbitrarily large, but the operator is not "greedy", as it does not try to process all of it, it is "lazy", it yields result only wneh asked to.



I seem not to be able to do easily and efficiently the same with strings in memory. E.g. if I read that file (or a part of it) into memory, I do not know how to iterate over the string in such a way, that a second invocation of the same matching operator would yield the second match and advance offset, which I'd be able to pick.



My attempts at constructing such behaviour from existing newlisp primitives were clumsy and terribly inefficient (e.g. there is an operator that will give only the first find, but then truncating the string will be very inefficient etc.)



Am I missing something? Is there a way to do efficient processing of largish strings in memory a la files, in the lazy manner?
#6
Usually short, very varied, some may be useful: 13  newlisp scripts submitted by people to http://snippets.dzone.com">http://snippets.dzone.com

http://snippets.dzone.com/tag/newlisp

Besides using the "newlisp" tag,  the site can be searched with

http://www.google.com/search?hl=en&as_q=newlisp&as_epq=&as_oq=&as_eq=&num=100&lr=&
as_filetype=&ft=i&as_sitesearch=snippets.dzone.com&as_qdr=all&
as_rights=&as_occt=any&cr=&as_nlo=&as_nhi=&safe=images

(restore the previous as one line without blanks)

This search will provide more newlisp-related material from that site
#7
/* note: I am not an exactly new member here, just changed my username because the old one became inaccessible */



Sometimes the topic of how to spread NewLisp to wider audiences floats up in the discussions. To my surprise I noticed that NewLisp is not advertised on Freshmeat  ( http://www.freshmeat.net">www.freshmeat.net )(!!) - which is THE MAJOR depository or at least the place where EVERYTHING gets announced and noticed



Shouldn't (we/the author) correct this glaring omission, and present it there with a blurb that says something to the effect of


  • -- tiny (less than 250k)

    -- a standalone executable, no need for a "systemwide installation"

    -- ability to create as if a standalone executable which is roughly (250k + your script size)

    -- speed on par with the likes of perl/...

    -- ability to work with C libraries directly from the scripting code

    -- virtually all APIs one needs for sysadmin work, web scripting, general purpose scripting, ...

    -- tiny size plus networking plus its standaloneness allow unusual applications, such as running in dozens of copies on the same machine or multiple copies running on many machines across the network, where all that is needed for this setup is copying 250k a few times.

    -- almost perfectly done modern documentation with cookbooks, a drastic difference from the old-fashioned bureaucratic formal ugliness which demands internat re-translation to practical terms and slows an aspiring programmer tremendously

    --  cross-platform, run it whever you wish

    -- and that it is a REAL and viable LISP/SCHEME in all programming aspects


An ultimate hacking tool, n'est pas?