Emacs中SML的基本操作

快捷键
Windows键盘中,这里C指的是Ctrl,M指的是Alt键
C-x C-c: Quit Emacs
C-g: Cancel the current action
C-x C-f: Open a file (whether or not it already exists)
C-x C-s: Save a file
C-x C-w: Write a file (probably more familiar to you as Save as…)
C-c C-s: 分割窗口并创建SML提示

C-w: Cut a highlighted region
M-w: Copy a highlighted region
C-k: Cut (kill) from the cursor to the end of the line
C-y: Paste (yank)
Some other useful commands:

C-x 2: Split the window into 2 buffers, one above the other (Use the mouse or C-x o to switch between them)
C-x 0: Undo window-splitting so there is only 1 buffer
C-x b: Switch to another buffer by entering its name
C-x C-b: See a list of all current buffers
Getting help within Emacs: In addition to the help button/menu on the right…

C-h: Hitting this will display a short message in the minibuffer: C-h (Type ? for further options).
C-h b: Key bindings. This lists all key bindings that are valid for the current mode. Note that key bindings change from mode to mode.
C-h a: Command apropos. After typing C-h a you can type a symbol and a buffer will appear that lists all symbols and functions that match that phrase.

SML提示中运行文件

use "filename.sml";

注释

(* notes *)

Function

fun pow(x: int, y: int) = 
    if y = 0
    then 1
    else x * pow(x, y-1)
val a = pow(2, 6)

Tuples

(e1, e2, ..., en)
ta * tb * ... * tn
#1 e, #2 e ..., #n e

Lists

empty list: em = []
lis = [v1, v2, ..., vn]
v0::lis = [v0, v1, v2, ..., vn]
null em = true
hd lis = v1
tl lis = [v2, ..., vn]

operator and operand don't agree: [3, 7, true]
approved: int list, bool list, int list list, (int * int list), 
(int list * int) list

Let expressions

fun silly(i: int)
    let 
        val x = 2
    in 
        x + i
    end
(* silly(0) = 2 *)

Nested Functions

fun silly2()
    let
        fun pow(x: int, y: int) = 
            if y = 0
            then 1
            else x * pow(x, y-1)
    in
        pow(2, 6)
    end    
(* 64 *)
(*the let part is used by the in part*)

Options

t option is a type for any type t
NONE has type 'a option (like [] has type 'a list)
SOME e has type t option if e has type t
isSOME has type 'a option -> bool
valOf has type 'a option -> 'a

instance:
val n = 2 : int
SOME (n) =  SOME 2 : int option
valOF (SOME (n)) = 2 : int

Booleans and Comparison Operations

Booleans:
e1 andalso e2 (like and, if one of e1 or e2 is false, then false)
e1 orelse e2 (like or, if one of e1 or e2 is true, then true)
not e1 (just contrast to e1)

Comparison:
=, <>, <, >, <=, >=
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值