Seven More Languages in Seven Weeks (读书笔记):Factor

本文介绍了Forth语言的基础概念及使用方法,包括条件语句、堆栈操作、高阶组合词以及元组等核心特性。文章通过实例展示了如何在Forth环境中定义词汇、使用条件判断,并介绍了基本的数据结构和内存管理技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Factor

  1. IN: scratchpad 20 9 * 5.0 / 32 + .
  2. Booleans:t/f
  3. Sequences:{ { "one" 1 } { "two" 2 } { "three" 3 } { "four" 4 } } //注意空格
  4. Quotations(匿名函数):[ 42 + ]
    1. call
  5. 条件语句
    1. IN: scratchpad 10 0 > [ "pos" ] [ "neg" ] if .
    2. 或 IN: scratchpad 10 0 > "pos" "neg" ? .
  6. Stack Shuffling
    1. dup, drop, nip, swap, over, rot, pick
  7. Higher-Order Words with Combinators
    1. IN: scratchpad 44.50 [ 0.05 * ] [ 0.09975 * ] bi //见鬼
      1. bi*
      2. bi@
      3. tri tri* tri@
  8. Vocabularies
    1. IN: scratchpad USE: present
    2. IN: scratchpad SYMBOL: tax-rate //What the Fuck!
    3.  : greeting ( name -- greeting ) "Hello, " swap append ; //定义一个库函数?IN: examples.greeter
    4.  : hello-world ( -- ) "world" greeting print ; //USE: examples.greeter
  9. Tuples
    1. TUPLE: cart-item name price quantity ; //?类型没有声明
      1. price>>(读)
      2. >>price(写)
      3. change-price
    2. "Seven Languages Book" 25.00 1 cart-item boa //By Order of Arguments
  10. 标准库(字典):略
  11. IN: scratchpad "demos" run
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值