ATS-CodeBook

659 views
Skip to first unread message

gmhwxi

unread,
Jan 9, 2018, 10:56:42 PM1/9/18
to ats-lang-users
Hi,

I have put together some code to demonstrate how to do various "practical" stuff in ATS:

https://github.com/ats-lang/ATS-CodeBook/

This is an ongoing project and new code will be added from time to time.

Functional programming done in ATS can be of quite different style from that in ML or Haskell. I would
really like to illustrate this point based on concrete examples. For instance, in ReadFromSTDIN3, a LINEAR
stream is built to handle user's input that may be interrupted by a signal (SIGALRM). As far as I can tell, this
kind of stream is unique in ATS; it provides high-level programming support while being very efficient both
time-wise and memory-wise.

Also, I would really like to emphasize the use of npm-based packages for constructing programs in ATS. This
is a great way for people to share code. I will try to say more on this later.

Cheers,

--Hongwei

gmhwxi

unread,
Jan 15, 2018, 12:07:53 PM1/15/18
to ats-lang-users
FYI.

I have just added the following two examples:

https://github.com/ats-lang/ATS-CodeBook/tree/master/RECIPE/Hangman
https://github.com/ats-lang/ATS-CodeBook/tree/master/RECIPE/Hangman2

Hangman implements the famous word-guessing game. The user input is handled
via a linear stream, a signature feature of the style of functional programming in ATS.
One may compare Hangman to the following example by Ryan King:

http://ryanking.com/blog/joy-of-ats-2-a-simple-game/

which handles the user input in the traditional ML style (which is largely taken from C).

In Hangman2, the user input is based on a simply web service, making it possible for
someone to play the game remotely.

Happy programming in ATS!!!

gmhwxi

unread,
Mar 8, 2018, 9:06:49 AM3/8/18
to ats-lang-users
FYI.

I added an example showing a way to parse a table in the CSV format:

https://github.com/ats-lang/ATS-CodeBook/tree/master/RECIPE/CSV-parsing

This example also shows you how to use ATS as a scripting language (if you
can get tcc (https://bellard.org/tcc/) installed).


On Tuesday, January 9, 2018 at 10:56:42 PM UTC-5, gmhwxi wrote:
Message has been deleted

Hongwei Xi

unread,
Mar 8, 2018, 10:25:36 PM3/8/18
to ats-lan...@googlegroups.com
Should be

bash ./NDX100.dats


On Thu, Mar 8, 2018 at 10:21 PM, Brandon Barker <brandon...@gmail.com> wrote:
Thanks for the example, 

When following the directions, I seem to run into a catastrophic error (of course, maybe I didn't follow the directions): here was my output:


brandon@brandon-750-170se-DevContainer:~/workspace/ATS-CodeBook/RECIPE/CSV-parsing
$ bash ./myread.dats
./myread.dats: line 1: DATA: command not found
./myread.dats: line 2: DATA: command not found
./myread.dats: line 3: //: Is a directory
./myread.dats: line 4: DATA: command not found
./myread.dats: line 5: DATA: command not found
./myread.dats: line 6: //: Is a directory
./myread.dats: line 8: share/atspre_staload.hats: No such file or directory
./myread.dats: line 11: share/HATS/atspre_staload_libats_ML.hats: No such file or directory
./myread.dats: line 12: //: Is a directory
./myread.dats: line 13: DATA: command not found
./myread.dats: line 15: extern: command not found
./myread.dats: line 16: fun: command not found
./myread.dats: line 17: print_gvhashtbl:: command not found
./myread.dats: line 18: syntax error near unexpected token `gvhashtbl'
./myread.dats: line 18: `print_type(gvhashtbl)'
brandon@brandon-750-170se-DevContainer:~/workspace/ATS-CodeBook/RECIPE/CSV-parsing
$ which tcc
/home/brandon/.nix-profile/bin/tcc
brandon@brandon-750-170se-DevContainer:~/workspace/ATS-CodeBook/RECIPE/CSV-parsing
$ which patscc
/home/brandon/.nix-profile/bin/patscc
brandon@brandon-750-170se-DevContainer:~/workspace/ATS-CodeBook/RECIPE/CSV-parsing
$ which patsopt
/home/brandon/.nix-profile/bin/patsopt
brandon@brandon-750-170se-DevContainer:~/workspace/ATS-CodeBook/RECIPE/CSV-parsing

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/854f2813-d1b5-4034-a078-3a0525199f8b%40googlegroups.com.

Brandon Barker

unread,
Mar 8, 2018, 10:47:02 PM3/8/18
to ats-lang-users
Oops..

Well, this is my first time running patscc in a couple of years but I don't remember it being this slow (has been churning away for 5 minutes; this is version 0.3.7 of ATS2):


$ which patscc
/home/brandon/.nix-profile/bin/patscc
brandon@brandon-750-170se-DevContainer:~/workspace/ATS-CodeBook/RECIPE/CSV-parsing
$ export PATSHOME=/home/brandon/.nix-profile
brandon@brandon-750-170se-DevContainer:~/workspace/ATS-CodeBook/RECIPE/CSV-parsing
$ make
\
/home/brandon/.nix-profile/bin/patscc -I./node_modules \
  -D_GNU_SOURCE -DATS_MEMALLOC_LIBC -o NDX100_dats NDX100.dats -latslib -ljson-c




# Hanging here, patscc is listed as using about 80% of a cpu core.
Should be

bash ./NDX100.dats


To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.

Hongwei Xi

unread,
Mar 8, 2018, 10:49:14 PM3/8/18
to ats-lan...@googlegroups.com
For this example, you need the latest version of ATS (ATS2-0.3.10).

To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.

Brandon Barker

unread,
Mar 10, 2018, 8:21:36 AM3/10/18
to ats-lang-users
I finally got around to killing the process ;-). I didn't get a lot of useful info from the kill since it was being run indirectly through make:

make: *** [Makefile:31: NDX100_dats] Terminated 

Would there be any interest in diagnosing this infinite loop in patscc further?

I didn't see a 0.3.10 release; but anyway, it is probably easier for me to follow the git repo that installing new releases. I tried this, but now have the following issue:

/home/brandon/workspace/ATS-CodeBook/RECIPE/CSV-parsing/myread.dats: 368(line=27, offs=1) -- 432(line=30, offs=38): error(1): the file [$PATSHOMELOCS/atscntrb-hx-csv-parse/mylibies.hats] is not available for inclusion.

What should PATSHOMELOCS be set to?

gmhwxi

unread,
Mar 10, 2018, 8:25:51 AM3/10/18
to ats-lang-users
export PATSHOMELOCS=./node_modules:./../node_modules:./../../node_modules:./../../../node_modules
Reply all
Reply to author
Forward
0 new messages