Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
hodzanassredin / Interface.Mod
Created November 23, 2023 12:48
Interfaces in Component Pascal
MODULE Interfaces;
IMPORT StdLog;
TYPE
MultiRec* = POINTER TO ABSTRACT RECORD END;
InterfacePrototype* = POINTER TO ABSTRACT RECORD END;
Iterator* = POINTER TO ABSTRACT RECORD(MultiRec) END;
@hodzanassredin
hodzanassredin / GcmMode.cs
Created July 30, 2023 20:02
GCM mode single file, pure C# based on https://github.com/bcgit/bc-csharp
using System;
using System.Diagnostics;
using System.Numerics;
using System.Text;
namespace Org.BouncyCastle.Crypto.Modes
{
internal static class Check
{
internal static void DataLength(bool condition, string message)
@hodzanassredin
hodzanassredin / unsigned.mod
Last active June 15, 2023 15:39
implementation of unsigned for CP
MODULE CryptoUnsigned;
IMPORT SYSTEM, StdLog;
TYPE
UNSIGNED8 = BYTE;
UNSIGNED16 = SHORTINT;
UNSIGNED32 = INTEGER;
UNSIGNED64 = LONGINT;
@hodzanassredin
hodzanassredin / paket.mod
Created May 12, 2023 21:22
poc of packages manager for bb
MODULE PaketView;
IMPORT Dialog, Strings, StdLinks, HyperHttp, TextRulers, Ports, Views, Files, TextViews, StdTextConv, TextControllers, TextModels, TextMappers, Stores, StdLog, StdCoder, Converters;
TYPE Package* = RECORD
data: ARRAY 4 OF TextMappers.String;
isInstalled : BOOLEAN;
depends : PackageList;
END;
PackageList = POINTER TO RECORD
package: Package;
@hodzanassredin
hodzanassredin / curry.mod
Created May 10, 2023 09:44
component pascal currying example
TYPE Vector* = POINTER TO ARRAY OF REAL;
Mapper2 = PROCEDURE (x,y:Vector) : Vector;
Mapper = POINTER TO ABSTRACT RECORD END;
Closure = POINTER TO RECORD (Mapper)
f : Mapper2;
x : Vector;
END;
PROCEDURE (m:Mapper) Apply(v : Vector) : Vector , NEW, ABSTRACT;
@hodzanassredin
hodzanassredin / clockhouse.mod
Created May 7, 2023 10:58
blackbox clickhouse http
MODULE HttpCmds;
(* This module provides the commands required to start and configure a singleton http or https server
and shows how to provide a REST API for Component Pascal modules.
It also includes an http test client.
For the REST API it implements a servlet (MyServlet) that can be registered with an http or https server e.g. under
the URI prefix /. With 'http://localhost/calc?x=1&y=2' a procedure Calc is called and its result returned in XML format.
The special request 'testPOST' opens a form that allows to call Calc by means of a POST method.
2016-07-26, Josef Templ, first version
@hodzanassredin
hodzanassredin / Graph.mod
Last active May 10, 2023 13:25
learning black box
MODULE LinalgGraph;
IMPORT v :=LinalgVector, p:= LinalgPolygon, Views, Ports, StdLog, Strings, Fonts, TextControllers, TextMappers,Properties;
CONST pointSize = Ports.point * 20;
TYPE
View = POINTER TO RECORD (Views.View) END;
Polygons* = POINTER TO RECORD
polygon* : p.Polygon;
next* : Polygons;
@hodzanassredin
hodzanassredin / constraints.fsx
Created April 29, 2023 15:09
constraints framework
type Message = | IHaveAValue
| ILostMyValue
[<ReferenceEquality>]
type Constraint = Constraint of (Message -> unit)
let forEachExcept (except:obj) (procedure: Constraint -> unit) (list: Constraint list) =
let rec loop (items: Constraint list) =
match items with
| [] -> ()
| h::t when System.Object.ReferenceEquals(h,except) -> loop t
@hodzanassredin
hodzanassredin / circuit.fsx
Created April 29, 2023 09:51
cicuits in fsharp
type Action = unit->unit
type Wire = (bool ref) * (Action list ref)
let getSignal ((s,_):Wire) : bool = s.Value
let setSignal ((s,fs):Wire) (signal:bool) =
if s.Value <> signal
then s.Value <- signal
List.iter (fun f->f()) fs.Value
@hodzanassredin
hodzanassredin / prolog.fsx
Last active April 28, 2023 07:38
sicp prolog reimplemented in fsharp
type Stream<'a> = | Nil | Cons of 'a * Lazy<Stream<'a>>
module Stream =
let cons a b = Cons(a,b)
let singleton a = cons a (Lazy.CreateFromValue(Nil))
let empty = Nil
let isEmpty = function
| Nil -> true
| Cons(a,_) -> false