MakrellPy, a language inspired by Hy #2549
hcholm
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
How did you decide to use braces for function calls instead of the more traditional parentheses? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Not directly related to Hy, and a bit of a shameless plug, but maybe it's of interest to some: I just released MakrellPy, a programming language that compiles to Python AST. It's part of the Makrell language family and partly inspired by Hy. Blurb from the home page:
The whole thing started as an experiment with metaprogramming in Hy, but after a while I decided to make it all from scratch. The result is quite different from Hy, but there are a lot of similar underlying features, such as the use of Python AST as the target, and the use of macros for metaprogramming. There are also multiline lambdas and a REPL. The most apparent difference is probably the use of infix operators.
I haven't studied Hy's macro system in detail, but it seems to solve macros a bit differently from MakrellPy. MakrellPy can import macros from other modules without including the source code, and I think it should be possible to do it completely transparent to the user in some way. Working on it.
The macro system is customisable through the use of
meta
blocks. Code in ameta
block is executed at compile time in a separate environment, and can be used to modify the AST. Macros are simply functions defined in the meta environment, withmacro
expressions simply being a shorthand for defining a function in the meta environment. The meta environment can define arbitrary values, like quoted code that can be inserted just by referencing it with an identifier in regular code. There is also support for defining new operators, which all are binary in MakrellPy.Instead of S-expressions, MakrellPy uses a base format that is a bit like an extended version of Hy/Lisp's S-expressions. It's a simple list-based format with support for tokens like strings, numbers, symbols, whitespaces and comments, but with three list types
( )
,[ ]
and{ }
. The base format is used by all the languages in the Makrell family, and is designed to be easy to parse and manipulate. At the base format level, nothing has semantic value except that lists are used to group tokens. Tokens like strings and numbers are distinguished purely by the string value at this level. It's up to the layers above to assign semantic values. E.g. MakrellPy uses{ }
for function calls and special forms, while MRON uses them for object literals, and MRML uses them for tags.Even the name Makrell is somewhat related to Hy. My first experiments were called 'Hyse', a name that just popped up in my head. Hyse is Norwegian (my native langue) for the fish haddock, but it's not a fish I feel particularly attached to. I prefer salmon ('laks' in Norwegian) and mackerel, and went for the Norwegian 'Makrell'. Which I thinks sounds fine for a programming language. It's a slight nod to Hy, and by coincidence you can associate with 'macro' and 'Haskell'. (Not that it will become purely functional, with I/O monads and all that jazz.)
GitHub page: https://github.com/hcholm/makrell-py
Visual Studio Code extension with syntax highlighting and basic diagnostics using the Language Server Protocol: https://marketplace.visualstudio.com/items?itemName=hcholm.vscode-makrell
Beta Was this translation helpful? Give feedback.
All reactions