{"id":13782678,"url":"https://github.com/jcupitt/asp","last_synced_at":"2025-03-16T03:10:17.555Z","repository":{"id":139896893,"uuid":"54554191","full_name":"jcupitt/asp","owner":"jcupitt","description":"interpreter for a tiny functional programming language","archived":false,"fork":false,"pushed_at":"2016-03-23T11:37:25.000Z","size":50,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-22T15:43:15.198Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcupitt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-03-23T11:22:06.000Z","updated_at":"2022-07-11T21:58:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ab40c5d-07a0-4132-a267-448529e14259","html_url":"https://github.com/jcupitt/asp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcupitt%2Fasp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcupitt%2Fasp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcupitt%2Fasp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcupitt%2Fasp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcupitt","download_url":"https://codeload.github.com/jcupitt/asp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243818205,"owners_count":20352629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:01:41.504Z","updated_at":"2025-03-16T03:10:17.531Z","avatar_url":"https://github.com/jcupitt.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# asp\n\nInterpreter for a tiny functional programming language.\n\nI wrote this back in 1986, I found the code kicking around, I thought it would\nbe fun to upload somewhere as a curiosity. It compiles, no idea if it works.\n\nIt was an experiment with an implementation strategy for string reduction. The\nlanguage I mostly used back then was Miranda. It used Turner's Combinators\nfor evaulation and I wondered if direct string reduction would be faster. \n\nasp evaluates lambdas like this:\n\n\tlambda x: x + 12 * x\n\ncompiles as:\n\n\tlambda A: A-\u003eB + 12 * B\n\nie. when instantiating the lambda, we write the pointer into A, then follow\nthe old value of the pointer to write into B. This way you can set all\ninstances of a bound variable in a single step, rather than using combinators\nto percolate values slowly downwards through the tree. \n\nThis will only work if the expression is unshared. Therefore asp keeps\nreference counts of objects, and reinstantiates afresh if a scrap of graph is\nshared.\n\nTo make instantiation quick, asp has a heap with variable-sized objects and\ndoes an instatiation with a straight memcpy(). Actually, there are two heaps\nand it does GC by simmple compaction.\n\nasp uses relative pointers to make memcpy() of tree fragments poossible. There\nare absolute pointers too. \n\nIt ended up being about 5x faster than Miranda, which pleased me. Though I\nactually went with plain combinators for the next \"compiler\" I did. \n\n# Original notes\n\n\n## Asp - simple applicative language.\n\nNotes for version 1.0\n\n```\nUsage: \n\tasp [-w - -c -h\u003cn\u003e -p\u003cn\u003e -a\u003cn\u003e -g\u003cn\u003e -f\u003cn\u003e] [filename filename ...]\n\nFlags:\t\n\t-w\tSupresses warnings.\n\t-\tSupress 'Starting evaluation' etc. messages.\n\t-c\tTurn on counting - statistics are given for various things. \n\t\tOnly useful for benchmarking.\n\t-O\tTurn on an optimiser ... this attempts to detect and remove \n\t\tcommon subexpressions, for a 10-20% speed improvement. Compile \n\t\ttime goes up a bit.\n\t-h\u003cn\u003e\tSet heap size. Default 60000 nodes.\n\t-p\u003cn\u003e\tSet parse heap size. Default 20000.\n\t-a\u003cn\u003e\tSet depth of application stack. Default 500.\n\t-g\u003cn\u003e\tSet depth of C pointer stack. Default 1000.\n\t-f\u003cn\u003e\tSet depth of fence stack. Default 100.\n```\n\nIf no filenames are given in the command line, asp reads from stdin.  After\nparsing all the files it generates a graph and starts reduction from 'main'.\n\nRun with (eg):\n\n\tasp -w prelude.a myprog.a\n\nprelude.a contains an Asp version of the Miranda standard prelude.\n\n### Asp primitives\n\n```\n#include \"pathname\"\t\n\t\t- Add file to list of files to be parsed.\n[], \"\"\t\t- The empty list.\n:\t\t- Infix cons.\nhd, tl\t\t- Head and tail of lists.\n[a,b,c]\t\t- List shorthand; same as a:b:c:[].\n[1..]\t\t- The infinite list [1,2,3,4,5,..].\n[1,3..]\t\t- The infinite list [1,3,5,7,9,..]. Can go down too.\n[1..10]\t\t- The list [1,2,3,4,5,6,7,8,9,10].\n[1,3..11]\t- The list [1,3,5,7,9,11]. As with [1,3..] can count up or \n\t\t  down.\n'a'\t\t- char.\ncode, decode\t- char -\u003e num and num -\u003e char.\n\"Hello world\\n\"\t- List of char. Most of the C escape sequences are allowed.\nerror \u003cexpr\u003e\t- Stop with an error message on stderr. Look out for loops in \n\t\t  the error expression!\n.\t\t- Function composition.\n+,-,*,/\t\t- Infix arithmetic ops. '-' can also be prefix.\ntrue,false\t- Boolean truth values.\nand,or\t\t- Infix logical ops.\n~\t\t- Not.\n\u003c\u003e,=,\u003c,\u003e,\u003e=,\u003c=\t- Infix relational ops.\nread \"pathname\"\t- Return the file as a list. Eg. read \"/dev/tty\" returns the \n\t\t  list of chars typed at the terminal.\n\"name\" write \u003cexpr\u003e\n\t\t- The result of evaluating the expr is written to the file. \n\t\t  Always returns true. Sorry it's infix.\n```\n\nAll the usual precedences and associativities are followed.\n\n### Asp syntax\n\nFunction definitions look like:\n\n\tfac n\t= 1, n\u003c2;\n\t\t= n * fac (n-1);\n\nWrite the function name, names for arguments and a list of possible right hand\nsides qualified by guard expressions. During evaluation, each of the guards is\nevaluated in turn (from the top). The result of the function is the expression\ncorresponding to the first guard to evaluate to true. The last rhs can have no\nguard and is the default.\n\nEverything following a % up to end of line is ignored.  Local definitions are\nenclosed in curly braces following the function. For example:\n\n\t% Insert sort a list of num or char.\n\tsort list \n\t\t= [], list=[];\n\t\t= insert (hd list) (sort (tl list));\n\t\t{\tinsert x list \n\t\t\t\t= [x], list = [];\n\t\t\t\t= x:list, x \u003c= a;\n\t\t\t\t= a:(insert x rest);\n\t\t\t\t{\ta = hd list;\n\t\t\t\t\trest = tl list;\n\t\t\t\t}\n\t\t}\n\nLocal definitions are slightly slower that global definitions.\n\n### Bugs and problems\n\nIt would be nice if it were not necessary to type in all those )%!\"#$ semi-\ncolons. Debugging is difficult without an interactive 'suck it and see' mode.\nIt would be nice if there was a type system! Local recursion is broken .. \nit makes the GC leak. It would be nice if hd/tl/+ etc. were functions rather\nthan built in operators.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcupitt%2Fasp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcupitt%2Fasp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcupitt%2Fasp/lists"}