#12427712 · 30 Jan 2009, 01:46 · · პროფილი · პირადი მიმოწერა · ჩატი
ტემპლეტების და იტერატორების ამბავში გამოიყენება სინტაქსური სუროგატი , ე წ ფუნქციონალური პროგრამირების ნოტაცია. ვიკი პედიაში პირდაპირაა ამ ყველაფრის სახელი აღნიშნული რო ესაა სინტაქსური შაქარი. ჯერ არის და for_each ვერ დავამუღამე და კლასიკურ სტილში
ჩემი კოდია List<int> target = new List<int>(); List<int> source_list = new List<int>(); int trans1,trans2; //for (int i = 0; i < 10; i++) { source_list.Add(i*50); } for (int i = 0; i < source_list.Count; i++) { trans1 =G(source_list[i]); trans2 =F(trans1); target.Add(trans2); }
--------------------------------- ვიკიდან ამოწერილი ლისტინგი
Coding styles
Imperative programs tend to emphasize the series of steps taken by a program in carrying out an action, while functional programs tend to emphasize the composition and arrangement of functions, often without specifying explicit steps. A simple example of two solutions to the same programming goal (using the same multi-paradigm language Python) illustrates this.
# imperative style target = [] # create empty list for item in source_list: # iterate over each thing in source trans1 = G(item) # transform the item with the G() function trans2 = F(trans1) # second transform with the F() function target.append(trans2) # add transformed item to target
A functional version has a different feel to it:
# functional style # FP-oriented languages often have standard compose() compose2 = lambda A, B: lambda x: A(B(x)) # Define how to apply two generic transformations target = map(compose2(F, G), source_list) # Apply two specific functions F and G to each item in source
In contrast to the imperative style that describes the steps involved in building target, the functional style describes the mathematical relationship between source_list and target.
In practice in Python that code is often written with a list comprehension, a form of syntactic sugar for the for loop with implicit append:
target = [F(G(item)) for item in source_list]
ღირს თუ არა ამ ტექნოლოგიის გამოყენება და რამდენად ღირებულია ეს ყველაფერი?
ამ ახალ სტილს რუბი სტილსაც უძახიან .
ვიკიზე კი ვკითხულობთ რომ ეს კარგად დავიწყებული ძველია
Functional programming has its roots in the lambda calculus, a formal system developed in the 1930s to investigate function definition, function application, and recursion. Many functional programming languages can be viewed as embellishments to the lambda calculus.[1]
--------------------
დიქტატ 2 ები ,ორატ 2 ები,ღ 2 ები ყველა ერთი სახეობის სხვადასხვა განშტოებებია . საერთო წინაპარი ყავდათ მაშ....
გვახსოვდეს svani67
|