This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html Set by lizmat on 8 June 2022. |
|||
shalokshalom | When I want to write a simple transpiler from one language to another (none of who are Raku) what tools would you recommend? | 06:46 | |
11:37
stanrifkin joined
|
|||
antononcube | Look at the “LLM::*” packages. | 12:01 | |
shalokshalom | thanks a lot | 12:25 | |
how are large language models involved | 12:27 | ||
cdn.discordapp.com/attachments/768...97fdd& | |||
antononcube | It is easy to make an LLM function that translates from one programming language to another. An ad hoc prompt can be crafted or the “CodeWriterX” prompt can be used. For the ad hoc prompt using the prompt “NothingElse” would be helpful. | 12:30 | |
For example: use LLM::Functions; use LLM::Prompts; my $conf = llm-configuration(‘chatgpt’, model => “gpt-4.1-mini”, max-tokens => 8192, temperature => 0.45); my &fTrans = llm-function( -> $code, $lang = ‘Raku’ { llm-prompt(“CodeWriterX”)($lang) ~ “\n\n” ~ $code}, e => $conf) | 12:37 | ||
So, you can call &fTrans on certain code string like this: my $code = q:to/END/; 100.rand xx 20 END say &fTrans($code, ‘Python’) | 12:40 | ||
shalokshalom | but I would need to run a model | 12:49 | |
I am trying to run a transpiler 😅 | |||
Like, a pure function | |||
not an unreliable llm implementation, that costs tons of ressources and produces a different outcome every time | 12:50 | ||
antononcube | Sure. Then use LLaMA models (run locally, on your computer or sever.) For example, specialized code generators from DeepSeek provided here: github.com/Mozilla-Ocho/llamafile . | 13:03 | |
The outcome is not necessary "different time" and it can be "managed" i.e. made faster and more relible. | 13:04 | ||
BTW, I completely understand and share your point of view. To large extend that is why I deal a lot with LLMs. | 13:05 | ||
14:07
stanrifkin left
14:18
stanrifkin joined
|
|||
sdomi | "how to make a transpiler" -> "oh, use an LLM" is really sad to read. | 16:26 | |
at this point you're writing a prompt for a glorified markov chain, NOT raku | |||
and this isn't the #llm-beginners channel, is it? | 16:27 | ||
@shalokshalom depends on whether you want to write everything yourself or want to use libraries. In latter option, look for a parser generator; if the languages are close enough together, you may be able to get around with very minimal intermediate representation | 16:30 | ||
raku has the included `grammar` functionality which would work just fine for a very simple transpiler | 16:31 | ||
if you don't like parser generators (just like me ;p) then you need to write your own parser, tokenizer, etc.; check out craftinginterpreters.com - the first few chapters should help you lots | 16:33 | ||
coranila | wow gatekeeping is very raku and butterfly friendly | 16:34 | |
that's to say, those first three lines couldve just not been there i think | 16:35 | ||
no pointing finers or flinging blame here, just stating a fact, i think everyone knows what i mean | |||
antononcube | @sdomi "and this isn't the #llm-beginners channel, is it?" -- yes, it is, if LLMs are used via Raku. | 17:37 | |
Also, of course, LLMs can be fairly successfully used to generate grammars and "transpiler" code. | 17:39 | ||
dr.shuppet | "Just call an LLM" is a very disappointing answer to "I want to write a transpiler in a language with native support for grammars" | 17:50 | |
17:55
sdomi left
|
|||
coranila | can we all agree on the compromise that asking an LLM what a specific transpiler might look like can be a good idea instead of starting a fight about a new kind of tool that isn't going to go away? | 18:02 | |
note that this must not be extended to homotopy; it does not imply that no one should talk to anyone anymore | 18:03 | ||
it just means that maybe instead of arguing about the fact that a new tool with outrageous implications exists | |||
we try to be constructive? | 18:04 | ||
again, not accusing anyone, just trying to remind people that drama for drama's sake isn't going to fix issues or complete features, neither in rakudo nor your own projects | 18:06 | ||
antononcube | @dr.shuppet & @sdomi I am looking at the definition of transcompiler in Wikipedia, en.wikipedia.org/wiki/Source-to-so..._compiler, > A source-to-source translator, source-to-source compiler (S2S compiler), transcompiler, or transpiler1[3] is a type of translator that takes the source code of a program written in a programming language as its input and produces an equivalent source code in the | 18:07 | |
same or a different programming language, usually as an intermediate representation. | |||
So, it seems that the LLM-based code implements are transcomilier. (Usin two lines of Raku code.) | 18:08 | ||
librasteve | if the languages have BNF definitions then perhaps raku.land/zef:raku-community-modul...ammar::BNF would be helpful ... either way a raku Grammar would be my go to for this | 19:31 | |
antononcube | "EBNF::Grammar" is better!! | 19:46 | |
The interaction with LLMs for making grammars and visualizing them is exemplified here: rakuforprediction.wordpress.com/20...-grammars/ | 19:56 | ||
librasteve | i have no experience, but at 10,000' it seems to me that a great use of LLMs would be to help write a transpiler - but that they are too variable to be relied on to be the sausage machine itself | 20:00 | |
20:05
librasteve_ joined
|
|||
antononcube | Right. The "bigger picture" is to use a combination of grammars, DSL examples, and LLM prompts for making source-to-source translations. | 20:20 | |
For example, using the data of "DSL::Examples" is not that hard to make a reliable LLM source-to-source translator for the corresponding DSLs. | 20:22 | ||
In general -- as we have discussed before -- Raku should have grammars for many programming languages and DSLs in order to facilitate those kind of translations. | 20:24 |