Skip to content

Latest commit

 

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

So by example

A hands-on introduction to Solod (So) — a subset of Go that translates to C.

This repo contains small examples that show individual language, concurrency, stdlib, and safety features, as well as larger apps that demonstrate how everything fits together.

Language

Hello worldValuesVariablesConstantsForIf/elseSwitchArraysSlicesMapsFunctionsMultiple returnsVariadic functionsFor-rangePointersStrings and runesStructsMethodsInterfacesEnumsErrorsPanicDefer

Concurrency

ThreadsChannelsChannel synchronizationChannel bufferingChannel timeoutNon-blocking channelsClosing channelsWorker poolsWorker pools w/channelsMutexesAtomic counters

Standard library

MemoryC interopSlicesMapsStringsTimeUnix timeTime formatRandom numbersNumber parsingSortingCustom sortJSONReading filesWriting filesScanningFile pathsDirectoriesTemp filesTestingBenchmarking Command lineEnv variablesLoggingTCP serverExit

Safety

Dangling pointerDivide-by-zeroMemory leakNil dereferencePanic mode

Apps

Coreutils: cat, cut, head, sort, uniq, wc

Count word frequencies by serge-hulne

Curl interop

DuckDB shell by Lorenzo Mangani

FreeSWITCH module by seven1240

Key-value store with SQLite interop

Reverse lines in file

TCP echo server and client.

Running the code

Install the latest versions of the So compiler and standard library:

go install solod.dev/cmd/so@6118636840f7
go get solod.dev@6118636840f7

Run a specific example locally with the so run command:

so run lang/05-for
so run apps/head -n 4 data/jenny.txt

You'll need to have a C compiler installed and available as cc, or you can set a custom compiler by using the CC environment variable.

To see the generated C code, use the so translate command:

so translate -o lang/05-for/generated lang/05-for

Partially based on Go by Example by Mark McGranaghan, licensed under CC BY 3.0.

About

Solod by example

Resources

Stars

16 stars

Watchers

1 watching

Forks

Contributors

Languages