Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions t/caesar.bel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;; Caesar encoding/decoding
;; Ported from https://github.com/koka-lang/koka/blob/4ef04cd7cfa965c413a985dfaabbfb69a4c64d11/samples/basic/caesar.kk

(def prlf args
(map pr args)
(pr \lf))

(set char->int charn
int->char nchar)

(mac letdef ((f . fbody) . body)
`(let ,f (fn ,@fbody)
,@body))

(def encode (s|string (o shift|int 3))
(letdef (encode-char (c)
(if (~<= \a c \z)
c
(withs (base (- (char->int c) (char->int \a))
rot (mod (+ base shift) 26))
(int->char (+ rot (char->int \a))))))
(map encode-char s)))

(def caesar (s|string)
(encode s 3))

(prlf (caesar "hello"))

17 changes: 17 additions & 0 deletions t/example-caesar.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!perl -T
use 5.006;

use strict;
use warnings;

use Test::More;
use Language::Bel::Test;

plan tests => 1;

my $output = output_of_eval_file("t/caesar.bel");

is $output,
"khoor\n",
"caesar example works";