alexey_rom: (Default)
[personal profile] alexey_rom
Цитата из Masterminds of Programming:
Python probably has the reputation of supporting functional programming based on the inclusion of lambda, map, filter and reduce in the language, but in my eyes these are just syntactic sugar, and not the fundamental building blocks that they are in functional languages. The more fundamental property that Python shares with Lisp (not a functional language either!) is that functions are first-class objects, and can be passed around like any other object. This, combined with nested scopes and a generally Lisp-like approach to function state, makes it possible to easily implement concepts that superficially resemble concepts from functional languages, like currying, map, and reduce. The primitive operators that are necessary to implement those concepts are built into Python, where in functional languages, those concepts are the primitive operations. You can write reduce() in a few lines of Python. Not so in a functional language.

Перевод:
Считается, что Python поддерживает функциональное программирование, скорее всего из-за включения lambda, map, filter и reduce в язык. Но с моей точки зрения это просто синтаксический сахар, а не основные строительные блоки, которыми они являются в функциональных языках. Куда более фундаментальным свойством, общим для Python и Lisp (который тоже не функциональный язык!), является то, что функции — объекты первого класса, и могут передаваться так же, как и любой другой объект. Это, в сочетании с вложенными областями видимости и в общем близким к Lisp'у подходом к состоянию функций, позволяет легко реализовать возможности, поверхностно напоминающие о таких возможностях функциональных языков, как карринг, map, и reduce. В Python встроены примитивные конструкции, необходимые для реализации этих понятий; а вот в функциональных языках они сами и являются примитивными конструкциями. В Python достаточно нескольких строк, чтобы написать reduce(). В функциональных языках это не так.

Date: 2010-03-11 03:20 pm (UTC)
From: [identity profile] alexey-rom.livejournal.com
Серьёзно сомневаетесь?


contours f = [ (contour p, head (head p) == '!') | p <- map lines (endBy "END" f)]
               where contour p = map (read :: String -> Double) (words p)


endBy из Data.List.Split, а не из стандартной библиотеки, но в одну строчку пишется.

Date: 2010-03-11 03:25 pm (UTC)
From: [identity profile] alexey-rom.livejournal.com
Чуть ошибся в contour, здесь ведь p -- список строк:

contour p = map (map (read :: String -> Double) . words) (tail p)

Date: 2010-03-11 03:42 pm (UTC)
From: [identity profile] zevlg.livejournal.com
не пробовал, но кажется, что на завершающем файл ENDе обломается и выдаст неправильный контур

если серьёзно, то конечно не сомневался, но хотелось чтобы кто-нибудь *подоказывал* :)

Date: 2010-03-11 03:49 pm (UTC)
From: [identity profile] alexey-rom.livejournal.com
не пробовал, но кажется, что на завершающем файл ENDе обломается и выдаст неправильный контур
Ну тогда (init $ endBy "END" f).

Date: 2010-03-11 03:50 pm (UTC)
From: [identity profile] alexey-rom.livejournal.com
но хотелось чтобы кто-нибудь *подоказывал* :)
:)

Date: 2010-03-11 03:44 pm (UTC)
From: [identity profile] zevlg.livejournal.com
там ещё на реальных файлах в конце END бывает \r, поэтому у меня x[:3]

Date: 2010-03-11 03:26 pm (UTC)
From: [identity profile] lionet.livejournal.com
Вот блин. Спасибо за Data.List.Split. В хугле его нет, кстати.

Date: 2010-03-12 02:06 pm (UTC)
From: [identity profile] lionet.livejournal.com
Считай, что нет:

http://holumbus.fh-wedel.de/hayoo/hayoo.html#0:%5Ba%5D%20-%3E%20%5Ba%5D%20-%3E%20%5B%5Ba%5D%5D

Как можно найти endBy, если знаешь только примерную сигнатуру?

Date: 2010-03-12 02:09 pm (UTC)
From: [identity profile] palm-mute.livejournal.com
Никак, hayoo по типам не ищет.

Date: 2010-03-12 02:12 pm (UTC)
From: [identity profile] palm-mute.livejournal.com
С последним заявлением я поторопился

Profile

alexey_rom: (Default)
alexey_rom

April 2012

S M T W T F S
1 234567
89 1011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 30th, 2025 06:36 pm
Powered by Dreamwidth Studios