Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
OperatorGK
- Posts: 66
- Joined: 13 Jan 2015 06:55
#1
Post
by OperatorGK » 03 Feb 2015 02:41
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?
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#2
Post
by Ed Dyreen » 03 Feb 2015 13:04
What is Lambdas ? What does it do ?
-
Aacini
- Expert
- Posts: 1913
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#3
Post
by Aacini » 03 Feb 2015 13:52
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
-
rojo
- Posts: 26
- Joined: 14 Jan 2015 13:51
#4
Post
by rojo » 05 Feb 2015 15:21
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.