Skip to content

Instantly share code, notes, and snippets.

@arkenidar
Created April 15, 2026 10:59
Show Gist options
  • Select an option

  • Save arkenidar/e99f0c02c3d1b13dc686903bedebe998 to your computer and use it in GitHub Desktop.

Select an option

Save arkenidar/e99f0c02c3d1b13dc686903bedebe998 to your computer and use it in GitHub Desktop.
in Lua , show some "functional paradigm" paradigm-patterns ( such as "partial application" and "closures" ) and a Lua Module design-pattern
local M = {}
function M.somma(a,b)
return a + b
end
function M.prodotto(a,b)
return a * b
end
function M.successivo(a)
return M.somma(a,1)
end
function M.doppio(a)
return M.prodotto(a,2)
end
function M.triplo(a)
return M.prodotto(a,3)
end
function M.prodotto_parametrico(n)
local function un_prodotto_di(a)
return M.prodotto(a,n)
end
return un_prodotto_di
end
M.quadruplo = M.prodotto_parametrico(4)
M.quintuplo = M.prodotto_parametrico(5)
M.mezzo = M.prodotto_parametrico(0.5)
return M
--[[
f=require('funcs')
f.doppio(2)
4
f.doppio(3)
6
f.quadruplo(3)
12
f.quintuplo(3)
15
]]
--[[
arkenidar@infotool:~/code$ cd /home/arkenidar/code/ && ls
cpp_libsdl3_script_luajit_sol3_embed funcs.lua win_script
arkenidar@infotool:~/code$ rlwrap luajit
LuaJIT 2.1.1737090214 -- Copyright (C) 2005-2025 Mike Pall. https://luajit.org/
JIT: ON SSE3 SSE4.1 BMI2 fold cse dce fwd dse narrow loop abc sink fuse
> f = require'funcs'
> =f
table: 0x7f7423a1df88
> =f.successivo
function: 0x7f7423a14b48
> =f.doppio
function: 0x7f7423a1e158
> =f.triplo
function: 0x7f7423a1e190
> =f.quadruplo
function: 0x7f7423a1e0f0
> =f.quintuplo
function: 0x7f7423a1e818
> =f.mezzo
function: 0x7f7423a1e890
> =f.mezzo(108)
54
> =f.doppio(54)
108
> =f.quintuplo(3)
15
>
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment