Skip to content

Commit

Permalink
Merge pull request #293 from taisukef/Pkl
Browse files Browse the repository at this point in the history
add Pkl
  • Loading branch information
taisukef authored Feb 8, 2024
2 parents 3c084f3 + 6647fb4 commit 3078472
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ the narrower the range, the longer the code, and the forward matching will tell

## Supported Languages

104 languages supported
105 languages supported

([JavaScript](#in-JavaScript-HTML) / [TypeScript](#in-TypeScript-Deno) / [Zen](#in-Zen) / [C](#in-C) / [C++](#in-C-1) / [C#](#in-C-2) / [Swift](#in-Swift) / [Java](#in-Java) / [Python](#in-Python) / [Ruby](#in-Ruby) / [PHP](#in-PHP) / [Go](#in-Go) / [Kotlin](#in-Kotlin) / [Dart](#in-Dart) / [Rust](#in-Rust) / [Haskell](#in-haskell-ghc-84x-or-later) / [OpenVBS](#in-OpenVBS) / [VBScript](#in-VBScript) / [Visual Basic](#in-Visual-Basic) / [Scala](#in-Scala) / [R](#in-R) / [GAS](#in-GAS-Google-App-Script) / [Nim](#in-Nim) / [Lua](#in-Lua) / [Perl](#in-Perl) / [Elixir](#in-Elixir) / [Groovy](#in-Groovy) / [D](#in-D) / [Julia](#in-Julia) / [Racket](#in-Racket) / [OCaml](#in-OCaml) / [Erlang](#in-Erlang) / [Clojure](#in-Clojure) / [F#](#in-F) / [Haxe](#in-Haxe) / [Scheme](#in-Scheme-R6RS) / [Common Lisp](#in-Common-Lisp) / [Elm](#in-Elm) / [Hack](#in-Hack) / [PureScript](#in-PureScript) / [CoffeeScript](#in-CoffeeScript) / [Objective-C](#in-Objective-C) / [Frege](#in-Frege) / [Eiffel](#in-Eiffel) / [Ada](#in-Ada) / [Free Pascal](#in-Free-Pascal) / [Crystal](#in-Crystal) / [Forth](#in-Forth) / [Bash](#in-Bash) / [AWK](#in-AWK) / [Vim script](#in-Vim-script) / [Vim9 script](#in-Vim9-script) / [IchigoJam BASIC](#in-IchigoJam-BASIC) / [GnuCOBOL](#in-GnuCOBOL) / [MoonScript](#in-MoonScript) / [Octave](#in-Octave) / [Emacs Lisp](#in-Emacs-Lisp) / [Fortran 90](#in-Fortran-90) / [MariaDB SQL/PSM](#in-MariaDB-SQL) / [PL/pgSQL](#in-PLpgSQL) / [Tcl](#in-Tcl) / [V](#in-V) / [Pike](#in-Pike) / [Io](#in-Io) / [Wren](#in-Wren) / [GNU Smalltalk](#in-GNU-Smalltalk) / [JScript](#in-JScript) / [Pharo](#in-Pharo) / [Scratch](#in-Scratch) / [Standard ML](#in-Standard-ML) / [なでしこ](#in-なでしこ) / [Kuin](#in-Kuin) / [ClojureScript](#in-ClojureScript) / [HSP](#in-HSP) / [Reason](#in-Reason) / [THPL](#in-THPL) / [Janet](#in-Janet) / [Phel](#in-Phel) / [Raku](#in-Raku) / [文言](#in-文言) / [Vala](#in-Vala) / [SmileBASIC](#in-SmileBASIC) / [Small Basic](#in-Small-Basic) / [Flix](#in-Flix) / [PowerShell](#in-PowerShell) / [Koka](#in-Koka) / [Zig](#in-Zig) / [BanchaScript](#in-BanchaScript) / [AssemblyScript](#in-AssemblyScript) / [Clawn](#in-Clawn) / [FORTRAN 77](#in-FORTRAN-77) / [orelang](#in-orelang) / [Laze](#in-Laze) / [WebAssembly](#in-WebAssembly) / [Nelua](#in-Nelua) / [Roland](#in-Roland) / [ReScript](#in-ReScript) / [Effekt](#in-Effekt) / [Ceylon](#in-Ceylon) / [Mochi](#in-Mochi) / [Neko](#in-Neko) / [NekoML](#in-NekoML) / [LLVM IR](#in-LLVM-IR) / [Mojo](#in-Mojo))
([JavaScript](#in-JavaScript-HTML) / [TypeScript](#in-TypeScript-Deno) / [Zen](#in-Zen) / [C](#in-C) / [C++](#in-C-1) / [C#](#in-C-2) / [Swift](#in-Swift) / [Java](#in-Java) / [Python](#in-Python) / [Ruby](#in-Ruby) / [PHP](#in-PHP) / [Go](#in-Go) / [Kotlin](#in-Kotlin) / [Dart](#in-Dart) / [Rust](#in-Rust) / [Haskell](#in-haskell-ghc-84x-or-later) / [OpenVBS](#in-OpenVBS) / [VBScript](#in-VBScript) / [Visual Basic](#in-Visual-Basic) / [Scala](#in-Scala) / [R](#in-R) / [GAS](#in-GAS-Google-App-Script) / [Nim](#in-Nim) / [Lua](#in-Lua) / [Perl](#in-Perl) / [Elixir](#in-Elixir) / [Groovy](#in-Groovy) / [D](#in-D) / [Julia](#in-Julia) / [Racket](#in-Racket) / [OCaml](#in-OCaml) / [Erlang](#in-Erlang) / [Clojure](#in-Clojure) / [F#](#in-F) / [Haxe](#in-Haxe) / [Scheme](#in-Scheme-R6RS) / [Common Lisp](#in-Common-Lisp) / [Elm](#in-Elm) / [Hack](#in-Hack) / [PureScript](#in-PureScript) / [CoffeeScript](#in-CoffeeScript) / [Objective-C](#in-Objective-C) / [Frege](#in-Frege) / [Eiffel](#in-Eiffel) / [Ada](#in-Ada) / [Free Pascal](#in-Free-Pascal) / [Crystal](#in-Crystal) / [Forth](#in-Forth) / [Bash](#in-Bash) / [AWK](#in-AWK) / [Vim script](#in-Vim-script) / [Vim9 script](#in-Vim9-script) / [IchigoJam BASIC](#in-IchigoJam-BASIC) / [GnuCOBOL](#in-GnuCOBOL) / [MoonScript](#in-MoonScript) / [Octave](#in-Octave) / [Emacs Lisp](#in-Emacs-Lisp) / [Fortran 90](#in-Fortran-90) / [MariaDB SQL/PSM](#in-MariaDB-SQL) / [PL/pgSQL](#in-PLpgSQL) / [Tcl](#in-Tcl) / [V](#in-V) / [Pike](#in-Pike) / [Io](#in-Io) / [Wren](#in-Wren) / [GNU Smalltalk](#in-GNU-Smalltalk) / [JScript](#in-JScript) / [Pharo](#in-Pharo) / [Scratch](#in-Scratch) / [Standard ML](#in-Standard-ML) / [なでしこ](#in-なでしこ) / [Kuin](#in-Kuin) / [ClojureScript](#in-ClojureScript) / [HSP](#in-HSP) / [Reason](#in-Reason) / [THPL](#in-THPL) / [Janet](#in-Janet) / [Phel](#in-Phel) / [Raku](#in-Raku) / [文言](#in-文言) / [Vala](#in-Vala) / [SmileBASIC](#in-SmileBASIC) / [Small Basic](#in-Small-Basic) / [Flix](#in-Flix) / [PowerShell](#in-PowerShell) / [Koka](#in-Koka) / [Zig](#in-Zig) / [BanchaScript](#in-BanchaScript) / [AssemblyScript](#in-AssemblyScript) / [Clawn](#in-Clawn) / [FORTRAN 77](#in-FORTRAN-77) / [orelang](#in-orelang) / [Laze](#in-Laze) / [WebAssembly](#in-WebAssembly) / [Nelua](#in-Nelua) / [Roland](#in-Roland) / [ReScript](#in-ReScript) / [Effekt](#in-Effekt) / [Ceylon](#in-Ceylon) / [Mochi](#in-Mochi) / [Neko](#in-Neko) / [NekoML](#in-NekoML) / [LLVM IR](#in-LLVM-IR) / [Mojo](#in-Mojo) / [Pkl](#in-Pkl))

supported languages list / サポート言語一覧
https://github.com/taisukef/Geo3x3/blob/master/langlist.csv
Expand Down Expand Up @@ -2361,6 +2361,26 @@ to run:
$ mojo simple_geo3x3.mojo
```

### in Pkl
[Pkl](https://pkl-lang.org/)
[geo3x3.pkl](https://github.com/taisukef/Geo3x3/blob/master/geo3x3.pkl),
[simple_geo3x3.pkl](https://github.com/taisukef/Geo3x3/blob/master/simple_geo3x3.pkl)
```
import "geo3x3.pkl"
enc = geo3x3.encode(35.65858, 139.745433, 14)
dec = geo3x3.decode("E9139659937288")
```
setup:
```bash
$ curl -L -o pkl https://github.com/apple/pkl/releases/download/0.25.1/pkl-macos-aarch64
$ chmod +x pkl
```
to run:
```bash
$ ./pkl eval simple_geo3x3.pkl
```

## How to contribute
1. add a lang
2. add a lang section in [README.md](README.md) (ex. [Neko](#in-Neko))
Expand Down
51 changes: 51 additions & 0 deletions geo3x3.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module geo3x3

function encode_fn(code, level, i, lat, lng, unit) =
if (i >= level)
code
else
encode_fn(
code + "\(lng ~/ unit + lat ~/ unit * 3 + 1)",
level,
i + 1,
lat - unit * (lat ~/ unit),
lng - unit * (lng ~/ unit),
unit / 3.0
)

function encode(lat, lng, level) =
encode_fn(
if (lng < 0.0) "W" else "E",
level,
1,
lat + 90.0,
if (lng < 0.0) lng + 180.0 else lng,
180.0 / 3.0
)

function decode_fn(code, lat, lng, level, unit, wflg) =
if (code.length == level)
List(
-90.0 + (lat + unit * 3.0 / 2.0),
if (wflg)
(lng + unit * 3.0 / 2.0) - 180.0
else
lng + unit * 3.0 / 2.0,
level,
unit * 3.0
)
else
decode_fn(
code,
lat + (code[level].toInt() - 1) ~/ 3 * unit,
lng + (code[level].toInt() - 1) % 3 * unit,
level + 1,
unit / 3.0,
wflg
)

function decode(code) =
if (code[0] == "W")
decode_fn(code, 0.0, 0.0, 1, 180.0 / 3.0, true)
else
decode_fn(code, 0.0, 0.0, 1, 180.0 / 3.0, false)
1 change: 1 addition & 0 deletions langlist.csv
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ Neko,neko,blacket,var,none,compile,https://github.com/taisukef/Geo3x3/blob/maste
NekoML,nml,blacket,var,none,compile,https://github.com/taisukef/Geo3x3/blob/master/Geo3x3.nml
LLVM IR,ll,blacket,none,none,compile,https://github.com/taisukef/Geo3x3/blob/master/geo3x3.ll
Mojo,mojo,indent,var,let,compile,https://github.com/taisukef/Geo3x3/blob/master/geo3x3.mojo
Pkl,pkl,none,none,let,script,https://github.com/taisukef/Geo3x3/blob/master/geo3x3.pkl
4 changes: 4 additions & 0 deletions simple_geo3x3.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import "geo3x3.pkl"

enc = geo3x3.encode(35.65858, 139.745433, 14)
dec = geo3x3.decode("E9139659937288")

0 comments on commit 3078472

Please sign in to comment.