Page 1 of 1

Lambdas or something alike...

Posted: 03 Feb 2015 02:41
by OperatorGK
Hey!
I made something alike lambdas:

Code: Select all

@echo off
set lambda=call:lambda

set func=%lambda%:echo\.\1\_\3

%func% THIS_WIIL_ECHO BUT_THIS_NOT AND_THIS_WILL

exit /B

:lambda:[code] [args]
setlocal
for /f "delims=: tokens=1*" %%a in ("%0") do set "code=%%b"
set "ccode=%code%"
call set "code=%%code:\*=%*%%"
call set "code=%%code:\1=%1%%"
call set "code=%%code:\2=%2%%"
call set "code=%%code:\3=%3%%"
call set "code=%%code:\4=%4%%"
call set "code=%%code:\5=%5%%"
call set "code=%%code:\6=%6%%"
call set "code=%%code:\7=%7%%"
call set "code=%%code:\8=%8%%"
call set "code=%%code:\9=%9%%"
call set "code=%%code:\_= %%"
call set "code=%%code:\:=;%%"
call set "code=%%code:\.=,%%"
call set "code=%%code:\@=&%%"
call set "code=%%code:\/=|%%"
call set "code=%%code:\]=>%%"
call set "code=%%code:\[=<%%"
call set "code=%%code:\0=%ccode%%%"
endlocal && %code%
exit /B

I have seen "macro" topics before, but this way is much simpler (and slower :( ). Can this be useful?

Re: Lambdas or something alike...

Posted: 03 Feb 2015 13:04
by Ed Dyreen
What is Lambdas ? What does it do ?

Re: Lambdas or something alike...

Posted: 03 Feb 2015 13:52
by Aacini
I don't know what a lambda is and you had not posted any reference, but this code produce the same output than yours:

Code: Select all

@echo off
set lambda=call:lambda

set func=echo \1\_\3

%lambda% THIS_WIIL_ECHO BUT_THIS_NOT AND_THIS_WILL

exit /B

:lambda
setlocal EnableDelayedExpansion
set code=%func:\_= %
set code=!code:\=%%!
call %code%
exit /B

Antonio

Re: Lambdas or something alike...

Posted: 05 Feb 2015 15:21
by rojo
A lambda is a throwaway function. I generally associate lambdas with JavaScript's replace functions. Something like:

Code: Select all

// This is JavaScript.
var count=0
"The quick brown fox".replace(/\w/g, function(m) { count++ });


... would count the letters in the string. There are 16. You're welcome.