基普:一种基于土耳其语格的编程语言
Kip: A programming language based on grammatical cases of Turkish

原始链接: https://github.com/joom/kip

## Kip:一种受语言学启发的编程语言 Kip 是一种实验性编程语言,探索语言学和类型论的交叉点,特别是利用土耳其语语法。它独特地将土耳其语名词格整合到其类型系统中,影响函数调用中参数的处理方式——只要格/类型不同,就可以灵活调整参数顺序。 Kip 不使用传统的语法,而是利用土耳其语形态学,包括格(主格、宾格、与格等)和元音和谐。它支持代数数据类型、泛型的类型变量、模式匹配和命名常量,所有这些都使用土耳其语语法表达。 Kip 并非用于生产环境;它是一种研究/教育工具。它包含用于整数和字符串的内置类型,以及基本运算和 I/O。该语言依赖于 TRmorph 工具包进行土耳其语形态分析,通过携带多个解析直到类型检查来处理歧义。 用户可以通过 REPL 探索 Kip,执行文件或生成 JavaScript 代码。一个浏览器游乐场也可用,从源代码构建。该项目正在积极开发中,因此语法和行为可能会发生变化。

黑客新闻 新的 | 过去的 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Kip: 一种基于土耳其语格的编程语言 (github.com/joom) 6点 由 todsacerdoti 1小时前 | 隐藏 | 过去的 | 收藏 | 讨论 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系 搜索:
相关文章

原文

Kip (meaning "grammatical mood" in Turkish) is an experimental programming language that uses Turkish grammatical cases as part of its type system. It demonstrates how natural language morphology—specifically Turkish noun cases and vowel harmony—can be integrated into programming language design.

This is a research/educational project exploring the intersection of linguistics and type theory, not a production programming language.

There is also a tutorial in Turkish and a tutorial in English that explains how to write Kip programs.

Note

Kip is experimental. Expect changes in syntax and behavior over time.

For you to get a taste of what Kip looks like, here is an example program that prompts the user to enter a number and then prints that many of the Fibonacci numbers:

(* İlk n Fibonacci sayısını yazdırır. *)
(bu tam-sayıyı) (şu tam-sayıyı) (o tam-sayıyı) işlemek,
  (onla 0'ın eşitliği) doğruysa,
    durmaktır,
  yanlışsa,
    bunu yazıp,
    şunu (bunla şunun toplamını) (onla 1'in farkını) işlemektir.

çalıştırmak,
  "Bir sayı girin:" yazıp,
  isim olarak okuyup,
  ((ismin tam-sayı-hali)
    yokluksa,
      "Geçersiz sayı." yazmaktır,
    n'nin varlığıysa,
      0'ı 1'i n'yi işlemektir).

çalıştır.

Turkish Grammatical Cases as Types

Kip uses Turkish noun cases (ismin halleri) to determine argument relationships in function calls:

Case Turkish Name Suffix Example
Nominative Yalın hal (none) sıfır
Accusative -i hali -i, -ı, -u, -ü sayıyı
Dative -e hali -e, -a sayıya
Locative -de hali -de, -da, -te, -ta listede
Ablative -den hali -den, -dan, -ten, -tan listeden
Genitive Tamlayan eki -in, -ın, -un, -ün sayının
Instrumental -le eki -le, -la, ile sayıyla
Possessive (3s) Tamlanan eki -i, -ı, -u, -ü, -si, -sı ardılı

Because Turkish cases mark grammatical relationships explicitly, Kip allows flexible argument ordering. These two calls are equivalent:

(5'le 3'ün farkını) yaz.
(3'ün 5'le farkını) yaz.

As long as arguments have different case suffixes or different types, Kip can determine which argument is which.

Define algebraic data types with Turkish syntax:

Bir doğruluk ya doğru ya da yanlış olabilir.

Bir doğal-sayı
ya sıfır
ya da bir doğal-sayının ardılı
olabilir.

Type variables are supported for generic data structures:

Bir (öğe listesi)
ya boş
ya da bir öğenin bir öğe listesine eki
olabilir.

Pattern match using the conditional suffix -sa/-se:

(bu doğruluğun) tersi,
  bu doğruysa, yanlış,
  yanlışsa, doğrudur.

Supports nested pattern matching, binders, and wildcard patterns (değilse):

(bu doğal-sayının) kopyası,
  bu sıfırsa, sıfır,
  öncülün ardılıysa, öncülün ardılıdır.

Define named constants with diyelim:

sıfırın ardılına bir diyelim.
birin ardılına iki diyelim.

Sequencing with -ip/-ıp/-up/-üp suffixes and binding with olarak:

selamlamak,
  isim olarak okuyup,
  ("Merhaba "yla ismin birleşimini) yazmaktır.

Built-in Types and Operations

Integers (tam-sayı):

  • Arithmetic: toplamı, farkı, çarpımı
  • Comparison: eşitliği, küçüklüğü, büyüklüğü
  • Other: öncülü, sıfırlığı, faktöriyeli

Strings (dizge):

  • uzunluğu - length
  • birleşimi - concatenation
  • tam-sayı-hali - parse as integer

I/O:

  • yazmak / yaz - print to stdout
  • okumak / oku - read from stdin
5'i yaz.              (* Integer literal with case suffix *)
"merhaba"'yı yaz.     (* String literal with case suffix *)
  1. Foma - finite-state morphology toolkit

    • macOS: brew install foma
    • Debian/Ubuntu: apt install foma libfoma-dev
    • Fedora: dnf install foma foma-devel
  2. Stack - Haskell build tool

Tip

If you only want to explore the language, you can start with stack exec kip after a successful build.

Clone this repository, then:

# Quick install (macOS/Linux)
chmod +x install.sh
./install.sh

# Or manual build
stack build

The TRmorph transducer is bundled at vendor/trmorph.fst.

# Start REPL
stack exec kip

# Execute a file
stack exec kip -- --exec path/to/file.kip

# Generate JavaScript
stack exec kip -- --codegen js path/to/file.kip

# Install to PATH
stack install

A browser playground can be built from source under playground/. It compiles the non-interactive runner (kip-playground) to wasm32-wasi and ships a small HTML/JS harness that runs Kip in the browser.

Note

The playground/dist/ directory is not included in the repository. You must build it locally following the instructions below.

See playground/README.md for prerequisites, toolchain setup, and build steps.

Kip stores a cached, type-checked version of each .kip file in a sibling .iz file. When you run a file again, Kip will reuse the .iz cache if both the source and its loaded dependencies are unchanged.

If you want to force a fresh parse and type-check, delete the .iz file next to the source.

Important

.iz files include a compiler hash. If the compiler changes, the cache is invalidated automatically.

app/
└── Main.hs            - CLI entry point

src/
├── Kip/
│   ├── AST.hs         - Abstract syntax tree
│   ├── Cache.hs       - .iz cache handling
│   ├── Eval.hs        - Interpreter
│   ├── Parser.hs      - Parser
│   ├── Render.hs      - Pretty-printing with morphological inflection
│   └── TypeCheck.hs   - Type checker validating grammatical case usage
└── Language/
    └── Foma.hs        - Haskell bindings to Foma via FFI

lib/
├── giriş.kip          - Prelude module loaded by default
├── temel.kip           - Core types
├── temel-doğruluk.kip  - Boolean functions
├── temel-dizge.kip     - String functions
├── temel-etki.kip      - I/O primitives
├── temel-liste.kip     - List functions
└── temel-tam-sayı.kip  - Integer functions

tests/
├── succeed/            - Passing golden tests (.kip + .out + optional .in)
├── fail/               - Failing golden tests (.kip + .err)
└── repl/               - REPL interaction tests

vendor/
└── trmorph.fst        - TRmorph transducer

Tests are in tests/succeed/ (expected to pass) and tests/fail/ (expected to fail).

Kip uses TRmorph for Turkish morphological analysis. When a word has multiple possible parses (e.g., "takası" could be "taka + possessive" or "takas + accusative"), Kip carries all candidates through parsing and resolves ambiguity during type checking.

For intentionally ambiguous words, use an apostrophe to force a specific parse: taka'sı vs takas'ı.

See LICENSE file.

联系我们 contact @ memedata.com