代码在Notepad ++中时,如何使用SMLNJ编译SML? [英] How to compile SML using SMLNJ while the code is in Notepad++?

查看:70
本文介绍了代码在Notepad ++中时,如何使用SMLNJ编译SML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SML完全陌生,我不知道如何使用与SML相关的任何东西.我应该使用SMLNJ编译器,并且当前正在使用Notepad ++进行编码.但是我如何准确地编译程序?是否将代码复制并粘贴到SMLNJ命令行中?还是我可以实际编写并编译代码的SMLNJ环境?请帮助!

I'm completely new to SML and I have no idea how to work with anything related to it. I am supposed to use the SMLNJ compiler and I'm currently coding using Notepad++. But how do I compile the program exactly? Do I copy and paste the code in the SMLNJ command line thing? Or is there an environment for SMLNJ I can actually code in and compile my code? PLEASE HELP!

推荐答案

如果用编译"来表示编译为独立的可执行文件",那么当您首次学习该语言作为完整答案时,不必担心有点牵连.从原则上讲,这是可能的,尽管似乎存在实际问题(例如个很好的答案).

If by "compile" you mean "compile to a stand-alone executable" -- don't worry about that when first learning the language as a full answer is somewhat involved. In principle it is possible, though there seems to be practical issues (as this excellent answer details).

另一方面,SML/NJ具有基于命令行的REPL(读取,评估,打印,循环),实际上它是编译器.它是增量编译器 -意味着它可以在当前定义的上下文中编译新定义的函数职能.首先,您将尝试直接输入REPL的简短代码段.很快,您将要用NotePad ++之类的代码编写代码.只需写入文件,将其保存为.sml扩展名,然后在REPL中输入

On the other hand, SML/NJ has a command-line based REPL (Read-Evaluate-Print-Loop) which actually is an compiler. It is an incremental compiler -- meaning that it compiles newly defined functions in the context of currently defined functions. At the very first you will be experimenting with short snippets typed directly into the REPL. Sooner rather than later you will want to write the code in something like NotePad++ . Just write the file, save it with a .sml extension, then in the REPL type

use "filename"; 

它会加载并编译您的定义.

and it loads and compiles your definitions.

以下是我有时使用的一个技巧.在我的文件顶部,我有这样的评论:

A trick that I sometimes use is the following. On the top of my files I have a comment like this:

(*   val _ = (use "C:/Programs/sets.sml", OS.Process.system "cls");      *)

这里 sets.sml 恰好是我在计算机上拥有的SML文件.编辑完文件后,我将其保存,然后将注释内容(以 val 开头并扩展为分号)复制到剪贴板,然后将其粘贴到打开的SML REPL中(使用单击命令窗口左上角的图标时,将弹出命令窗口的编辑菜单.这样会加载定义,并为您提供清晰的REPL,供您尝试定义.

Here sets.sml just happens to be an SML file I have on my machine. When I get done editing the file I save it and then copy the insides of the comment (beginning with val and extending to the semicolon) to the clipboard and then paste it into an open SML REPL (using the edit menu for the command window which pops up when you hit the icon in the upper left hand corner of the command window). This loads the definitions and presents you with a cleared REPL for experimenting with your definitions.

Notepad ++似乎缺少SML的语法定义文件(尽管它有一个用于F#的文件,可能足够接近).就个人而言,我使用 Textpad 来完成大部分SML.这不是开源的,但是 nagware 的价格合理,大致可与Notepad ++媲美.您可以从他们的网站下载有用的SML语法定义文件,该文件在逻辑上突出显示代码方面做得很好.我什至创建了一个Textpad工具(由于未知原因,该工具只能偶尔使用),用于自动保存文件,打开SML并在文件名上调用 use .

Notepad++ seems to lack a syntax definition file for SML (although it has one for F#, which might be close enough). Personally, I do most of my SML using Textpad. This isn't open source but is reasonably priced nagware which is roughly comparable to Notepad++. From their website you can download a useful SML syntax-definition file which does a nice job of logically highlighting your code. I even created a Textpad tool (which for unknown reasons only works sporadically) for automatically saving the file, opening SML, and invoking use on the file name.

这篇关于代码在Notepad ++中时,如何使用SMLNJ编译SML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆