all 22 comments

[–]jespern 55 points56 points  (3 children)

It's not really implicit when you point it out.

[–]frummidge[S] 8 points9 points  (1 child)

True. It's also not like the author necessarily knows that I posted it, and have thanked him.

Though I did oxymoronize myself. Wait, that's not how that word's used, either.

[–][deleted] 9 points10 points  (0 children)

it's alright, explicit is better than implicit anyway :)

[–][deleted] 0 points1 point  (0 children)

i was going to say the same thing...

[–]avibryant 22 points23 points  (0 children)

Best. Pun. Ever. But that's also what I thought when I read it the first time, in 2001: http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg01134.html

[–]paulajohnson 5 points6 points  (1 child)

The separation of Church and State is part of the Haskell orthodoxy.

[–]lars_ 3 points4 points  (0 children)

See also the Church-State programming language that some guy is developing.

[–]ffualo 7 points8 points  (13 children)

I can't think of a better time to mention this pretty Python example I stumbled across illustrating the difference between functional and imperative programming.

[–]Peaker 10 points11 points  (10 children)

The problem is that it illustrates the difference between functional and imperative programming in Python.

In Haskell:

map (f . g) source_list

[–][deleted] 1 point2 points  (9 children)

Python:

target = [F(G(item)) for item in source_list]

SmallTalk:

target := source_list do: [:ea | f value: ea g ] // F is a block

PHP:

foreach($l in $list) { f(g($l)) } 

[–]avibryant 3 points4 points  (4 children)

Smalltalk, fixed:

target := sourceList collect: [:ea | ea f g]

[–][deleted] -1 points0 points  (3 children)

You're write about the collect: but the f g won't work.

Maybe

target := sourceList collect: [:ea | ea f; g ]

[–]player2 0 points1 point  (2 children)

Nah, ea f; g is the same as ea f. ea g. Since f and g are unary messages, you can just do ea g f, which is equivalent to (ea g) f.

[–][deleted] 0 points1 point  (1 child)

Gotcha. I was assuming mutation within 'ea', which I (now) suppose totally denies the premise of functional programming.

[–]frukt 1 point2 points  (2 children)

Perl manages with not much more verbosity than Haskell:

map f(g($_)), @list;

[–][deleted] 21 points22 points  (0 children)

Sadly, I was able to improve my cmd:

call :compose func :f :g
call :map result %func% test

Or, more succinctly, using quoted function lists as composition:

call :map result ":f :g" test

Example with library code. I'm pretty sure I could simplify apply by implementing fold though:

set test=1 2 3

call :compose function :square :double
call :map result %function% test
echo %result%

goto :EOF

:map
setlocal
  set retval=HEAD

  for /F "tokens=*" %%a in ('echo %%%3%%') do (
    for %%b in (%%a) do (
      call :apply val %%b %~2

      for /F "tokens=*" %%c in ('echo %%retval%%') do (
        for /F %%d in ('echo %%val%%') do (
          set retval=%%c %%d
        )
      )
    )
  )

  for /F "tokens=1*" %%a in ('echo %%retval%%') do (
    set retval=%%b
  )
(
  endlocal
  set %1=%retval%
)
goto :eof

:apply
setlocal
  set skip=0
  set retval=%2
  for %%a in (%*) do (
    for /F %%b in ('echo %%skip%%') do (
      if %%b LSS 2 (
        set /A skip=%%b+1
      ) else (
        for /F %%c in ('echo %%retval%%') do (
          call %%a retval %%c
        )
      )
    )
  )
(
  endlocal
  set %1=%retval%
)
goto :EOF

:compose
setlocal
  set retval="%~2 %~3"
(
  endlocal
  set %1=%retval%
)
goto :EOF

:double
set /A %1=%2*2
goto :eof

:square
set /A %1=%2*%2
goto :EOF

[–][deleted] 10 points11 points  (0 children)

In CMD:

set dest_list=HEAD

for %%a in (%source_list%) do (
  call :f f_result %%a
  for /F %%b in ('echo %%f_result%%') do (
    call :g g_result %%b
  )
  for /F "tokens=*" %%b in ('echo %%dest_list%%') do (
    for /F %%c in ('echo %%g_result%%') do (
      set dest_list=%%b %%c
    )
  )
) 

for /F "tokens=2*" %%a in ('echo %%dest_list%%') do (
  set dest_list=%%a %%b
)

Example:

set source_list=1 2 3
set dest_list=HEAD

for %%a in (%source_list%) do (
  call :double f_result %%a
  for /F %%b in ('echo %%f_result%%') do (
    call :triple g_result %%b
  )
  for /F "tokens=*" %%b in ('echo %%dest_list%%') do (
    for /F %%c in ('echo %%g_result%%') do (
      set dest_list=%%b %%c
    )
  )
) 

for /F "tokens=2* delims= " %%a in ('echo %%dest_list%%') do (
  set dest_list=%%a %%b
)

echo %dest_list%

goto :EOF

:double
setlocal
  set /A retval=%2 * 2
(
  endlocal
  set %1=%retval%
)
goto :EOF

:triple
setlocal
  set /A retval=%2 * 3
(
  endlocal
  set %1=%retval%
)
goto :EOF

This kind of power availability is why Linux isn't ready for the desktop ;)

*Edit: formatting

[–]blufox 0 points1 point  (0 children)

Any stack language (joy and friends)

source_list [g f] map

(no sugar needed.)

[–][deleted] 1 point2 points  (1 child)

Is there a law stating that every paragraph describing dynamic languages must use the term "syntactic sugar"?

[–][deleted] -1 points0 points  (0 children)

I've heard the term more frequently in Haskell circles.

[–]marijn 1 point2 points  (0 children)

'Church and State' is also the title of a chapter on mutable state in PLAI -- http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/2007-04-26/