[m-users.] Parsing source files / tem-rewriting

Sean Charles (emacstheviking) objitsu at gmail.com
Fri Aug 16 17:05:25 AEST 2024


Agreed. It is without doubt the hardest language I have ever learned, I still struggle with it at times, and the code I write is probably 'awful' as I don't fully grok all the concepts to the Nth degree, solver types for example.... whooooosh straight over the top of my head.

What Mercury has provided me with is a means to help me think hard about the problem at hand, and then give me a rock solid basis on which to implement the solution with its types, type-classes. I've used the sub-types here and there but I find they sometimes make things harder, again, probably down to my lack of formal education in 'logic programming.

All the best and thanks again to "Team Core Mercury"!

> On 16 Aug 2024, at 07:04, Volker Wysk <post at volker-wysk.de> wrote:
> 
> Am Freitag, dem 16.08.2024 um 06:37 +0100 schrieb Sean Charles (emacstheviking):
>> Yes, there is something *special* that Mercury does to your mind!
> 
> I think it's its strictness and cleanness - the logic programming paradigm, with modes and determinism categories... And the type system too...
> 
> Cheers,
> Volker
> 
>> 
>>> On 15 Aug 2024, at 16:26, Volker Wysk <post at volker-wysk.de> wrote:
>>> 
>>> Hi, Sean!
>>> 
>>> I see, you've adopted the philosophy "Don't give in until it's done right." 
>>> 
>>> That's not bad, I've adopted it too, not very long ago. It was after I've learned Mercury.
>>> 
>>> Keep hacking, and make that transpiler of yours a success. :-)
>>> 
>>> Cheers,
>>> Volker
>>> 
>>> 
>>> Am Donnerstag, dem 15.08.2024 um 07:29 +0100 schrieb Sean Charles (emacstheviking):
>>>> 
>>>> 
>>>>> On 15 Aug 2024, at 04:18, Volker Wysk <post at volker-wysk.de> wrote:
>>>>> 
>>>>> Am Mittwoch, dem 14.08.2024 um 19:19 +0100 schrieb Sean Charles
>>>>> (emacstheviking):
>>>>>> Yes, I have resisted the urge to use it, Uncle Bens rule applies here!  :D
>>>>> 
>>>>> Hmm... I couldn't find out what Uncle Ben's rule is.
>>>> 
>>>> Ah, it's from a Spiderman movie:
>>>> "
>>>> https://en.wikipedia.org/wiki/With_great_power_comes_great_responsibility"
>>>> 
>>>> https://en.wikipedia.org/wiki/Uncle_Ben
>>>> Sorry!
>>>> 
>>>>> 
>>>>>> I am working on a FORTH engine in Mercury right now, it's going well, it
>>>>>> will basically expose the strictness of Mercury through a stack based
>>>>>> system... currently the core words are hand assembled but they have a very
>>>>>> common pattern so far, and when the dust settles I think there MIGHT be a
>>>>>> case for term rewriting to create that data.
>>>>> 
>>>>> You have a lot of projects. But what would you want to do with a Forth
>>>>> engine? Is it just for the fun of programming? ;-)
>>>> 
>>>> Well, a loooooooong time ago I wrote this, felt-lang.com <http://felt-lang.com/>, since then I have rewritten it in Haskell, SWI-Prolog and C as POCs but wasn't hasppy, then the Universe showed my Mercury. It's been a very rewarding journey since and lots of what I have learned has filtered into my daily coding, mostly improved rigour in thinking about things.
>>>> 
>>>> The concept of  a transpiler is not new, I've used HaXe in the past, but *I* have never written one, currently the Mercury version parses s-expressions into working C code, which compiles, but the more I got into the weeds, the more I realised that I wanted a faster REPL based interactive/explorative environment for the code render phase, with the view that users vould use a glue language for the AT-->Code part to do whatever they want with the parsed s-expression tree.
>>>> 
>>>> For reasons best known to me3, and to avoid triggering Greenspun's tenth law, I decided I needed a custom FORTH dialect and so now I find myself engaged in hand-to-keyboard, I already have implemented basic stack ops, basic arithmetic, and a bunch of words,
>>>> 
>>>> 
>>>> ➜  mercury-merth git:(main) ✗ ./dstack
>>>>  > words
>>>> 
>>>> System words:
>>>> * + - -> . .S .SEEVM .STATUS .STRICT / /MOD : ; >IOP >IOW BYE CLEARSTACK CONSTANT CR DROP DUP ELSE EMIT ENDIF IF MOD OVER RECURSE ROT SEE SPACE SPACES SWAP THEN TYPE T{ WORDS }T 
>>>> 
>>>> User words:
>>>> 
>>>> 
>>>>  > : hv "Hello Volker!" type cr ;
>>>> New word defined: hv
>>>>  > words
>>>> 
>>>> System words:
>>>> * + - -> . .S .SEEVM .STATUS .STRICT / /MOD : ; >IOP >IOW BYE CLEARSTACK CONSTANT CR DROP DUP ELSE EMIT ENDIF IF MOD OVER RECURSE ROT SEE SPACE SPACES SWAP THEN TYPE T{ WORDS }T 
>>>> 
>>>> User words:
>>>> HV 
>>>> 
>>>>  > hv
>>>> Hello Volker!
>>>>  > 
>>>> 
>>>> I implemented the test words, T{ -> }T early on, and I copy the relevant tests from the Forth standards site and so far all passing which feels nice, for example, from https://forth-standard.org/standard/core/IF
>>>> 
>>>> "If/Else/Then" suite
>>>> T{ : GI1 IF 123 THEN ; -> }T
>>>> T{ : GI2 IF 123 ELSE 234 THEN ; -> }T
>>>> T{  0 GI1 ->     }T
>>>> T{  1 GI1 -> 123 }T
>>>> T{ -1 GI1 -> 123 }T
>>>> T{  0 GI2 -> 234 }T
>>>> T{  1 GI2 -> 123 }T
>>>> T{ -1 GI1 -> 123 }T
>>>> 
>>>> 
>>>> My dialect will expose all the Mercury basic types and modules, the stack only allows int and string at the moment but I have some planned features to allow a Lua like table structure, stack signature checking, there is NO coercion of types, as I say, under the hood I intend to 'expose' Mercurys world view into the dialect, it will be a strict strict puppy that's for sure,
>>>> 
>>>> The other feature I've designed is Forth->Mercury, by analysing the stack signatures, I plan to generate raw Mercury code so I use the engine for rapid prototyping of code, then it can be printed and incorporated into my custom IDE as I go, the IDE being written in Mercury too, still on paper that one but heavily inspired by 'that Doug Englebart demo' and the Squeak Smalltalk Morphic engine.
>>>> 
>>>> So much to do, so little time.
>>>> 
>>>> And, it's *always* for the fun of programming!
>>>> 
>>>> :D
>>>> 
>>>> Sean
>>>> 
>>>> 
>>>> 
>>>>> 
>>>>> Cheers,
>>>>> Volker
>>>>> 
>>>>>> 
>>>>>> Thanks again.
>>>>>> Sean
>>>>>> 
>>>>>> 
>>>>>>> On 14 Aug 2024, at 19:16, Volker Wysk <post at volker-wysk.de> wrote:
>>>>>>> 
>>>>>>> Am Mittwoch, dem 14.08.2024 um 19:10 +0100 schrieb Sean
>>>>>>> Charles (emacstheviking):
>>>>>>>> That's the chap!
>>>>>>>> 
>>>>>>>> Thanks Volker, I just could see it, my brain was convinced it was in a folder!
>>>>>>> 
>>>>>>> That thing is ridiculously small, for what it does.
>>>>>>> 
>>>>>>> Enjoy it!  :-)
>>>>>>> 
>>>>>>> Bye, 
>>>>>>> V.W.
>>>>>>> 
>>>>>>>>> On 14 Aug 2024, at 19:00, Volker Wysk <post at volker-wysk.de> wrote:
>>>>>>>>> 
>>>>>>>>> Am Mittwoch, dem 14.08.2024 um 18:29 +0100 schrieb Sean Charles
>>>>>>>>> (emacstheviking):
>>>>>>>>>> Hi,
>>>>>>>>>> 
>>>>>>>>>> There was an example of term rewriting but I cannot seem to find it
>>>>>>>>>> anywhere!
>>>>>>>>>> 
>>>>>>>>>> Is there any code I can leverage to scan a .m file and produce an AST or
>>>>>>>>>> at least scan the terms... I know the rewrite example pretty has all the
>>>>>>>>>> answers I need but I just can't find it.
>>>>>>>>> 
>>>>>>>>> I think you mean samples/expand_terms.m.
>>>>>>>>> 
>>>>>>>>> Cheers,
>>>>>>>>> Volker
>>>>>>>>> _______________________________________________
>>>>>>>>> users mailing list
>>>>>>>>> users at lists.mercurylang.org
>>>>>>>>> https://lists.mercurylang.org/listinfo/users
>>>>>>>> 
>>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> _______________________________________________
>>>> users mailing list
>>>> users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>
>>>> https://lists.mercurylang.org/listinfo/users
>>> 
>>> _______________________________________________
>>> users mailing list
>>> users at lists.mercurylang.org
>>> https://lists.mercurylang.org/listinfo/users
>> 
>> 
> 
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org <mailto:users at lists.mercurylang.org>
> https://lists.mercurylang.org/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20240816/9e0028f8/attachment-0001.html>


More information about the users mailing list