Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 976 Categories, Downloaded 30.153.874 Times

Perl6::Currying 0.05

  Date Added: October 08, 2010  |  Visits: 636

Perl6::Currying

Report Broken Link
Printer Friendly Version


Product Homepage
Download (71 downloads)

Perl6::Currying is a Perl 6 subroutine currying for Perl 5. SYNOPSIS use Perl6::Currying; sub add ($a,$b) { $a + $b } # Define a sub with named params print add(1,2); # Call it my $incr = &add.prebind(a=>1); # Bind the $a argument to 1 # to create an increment subroutine print $incr->(3), "n"; # Increment a number The Perl6::Currying module lets you try out the new Perl 6 explicit higher-order function syntax in Perl 5. In Perl 6 any subroutine can be "partially bound". That is, you can supply some of its arguments and thereby create another subroutine that calls the original with those arguments automatically supplied. Subroutine parameters are partially bound by calling the prebind method on the subroutine. This method call returns a reference to a new subroutine that calls the original subroutine, inserting into its argument list the prebound arguments. For example: # Perl 6 code sub divide ($numerator, $denominator) { return $numerator / $denominator; } my $halve = ÷.prebind(denominator=>2); Note that its necessary to use the & sigil to indicate that the method CODE::prebind is to be called on a CODE object ÷, not the Whatever::prebind of the Whatever object returned by calling divide. To get the latter, we would write: divide().prebind(...) or: divide.prebind(...) Having prebound the denominator, if we now call the subroutine referred to by $halve the effect is to call divide with an automagically supplied denominator of 2. That is: # Perl 6 code print divide(42,2); # calls ÷...prints 21 print $halve(42); # calls ÷...prints 21 Its also possible to prebind all the arguments of a subroutine, either all at once: # Perl 6 code my $pi_approx = ÷.prebind(numerator=>22,denominator=>7); print $pi_approx(); # prints 3.14285714285714 or in stages: # Perl 6 code my $pi_legislated = $halve.prebind(numerator=>6); print $pi_legislated(); # prints 3 Note that we didnt need the & sigil before $halve since this syntax is unambiguously a call (through a reference to a CODE object) to CODE::prebind. You can also use the Perl 6 aliasing operator (:=) to create new named subroutines by partially binding existing ones. For example: # Perl 6 code &reciprocal := ÷.prebind(numerator=>1); print reciprocal(10) # prints 0.1 Parameter binding in Perl 5 The Perl6::Currying module allows you to use the same syntax in Perl 5. That is, you can supply some of the arguments to a (specially prototyped) Perl 5 subroutine and thereby create another subroutine that calls the original with those arguments automatically supplied. The new subroutine is created by calling the prebind method on the original subroutine. For example: # Perl 5 code use Perl6::Currying; sub divide ($numerator, $denominator) { return $numerator / $denominator; } my $halve = ÷.prebind(denominator=>2); Notes: As the above example implies, Perl6::Currying gives you the (limited) ability to declare Perl 5 subroutines with named parameters. Currently those parameters must be a list of comma-separated scalars, as shown above. Each parameter becomes a lexical scalar variable within the body of the subroutine. For forward compatibility, to prebind parameters in Perl 5, the Perl 6 method call syntax ($objref.methodname(...)) is used, rather than the Perl 5 syntax ($objref->methodname(...)). To be consistent with Perl 6, its still necessary to use the & sigil to indicate that the method to be called is CODE::prebind, not the prebind of the object returned by calling divide. Having prebound the denominator, if we now call the subroutine referred to by $halve the effect is to call divide with an automagically supplied denominator of 2. That is: # Perl 5 code print divide(42,2); # calls ÷...prints 21 print $halve->(42); # calls ÷...prints 21 Note that since these are just normal Perl 5 subroutine calls, the Perl 5 call-through-reference syntax ($subref->(...)) is used, rather than the Perl 6 syntax ($subref.(...)). Its also possible to prebind all the arguments of a subroutine, either all at once: # Perl 5 code use Perl6::Currying; my $pi_approx = ÷.prebind(numerator=>22,denominator=>7); print $pi_approx->(); # prints 3.14285714285714 or in stages: # Perl 5 code use Perl6::Currying; my $pi_legislated = $halve.prebind(numerator=>6); print $pi_legislated(); # prints 3 You can also use Perl 5 typeglobs to create new named subroutines by partially binding existing ones. For example: # Perl 5 code *reciprocal = ÷.prebind(numerator=>1); print reciprocal(10) # prints 0.1.

Requirements: No special requirements
Platforms: Linux
Keyword: Code Libraries Perl Print Programming Subroutine
Users rating: 0/10

License: Freeware Size: 5.12 KB
PERL6::CURRYING RELATED
Libraries  -  Benchmark 5.8.8
Benchmark is a Perl module with benchmark running times of Perl code. SYNOPSIS use Benchmark qw(:all) ; timethis ($count, "code"); # Use Perl code in strings... timethese($count, { Name1 => ...code1..., Name2 => ...code2..., }); #...
12.2 MB  
Programming  -  Transmuter Programming Language 0.9.2
Transmuter Programming Language is an extremely dynamic, biologically-inspired prototyping language providing a framework for experimenting with naturally evolving systems of objects over the net, and for exploring new ideas about recombinant...
348.16 KB  
Libraries  -  ExtUtils::CBuilder 0.19
ExtUtils::CBuilder is a Perl module to compile and link C code for Perl modules. SYNOPSIS use ExtUtils::CBuilder; my $b = ExtUtils::CBuilder->new(%options); $obj_file = $b->compile(source => MyModule.c); $lib_file = $b->link(objects =>...
19.46 KB  
Programming  -  Code Snippets Database 0.8beta2
Code Snippets Database (CSD) is a web-based tool which helps you organize your code snippets for different programming languages. It supports both categories and tags for easy browsing and it has a syntax highlighter.
368.12 KB  
Education  -  Dream in code 1.0.0.0
This application provides latest blogs, tutorial, forum discussion, new programming tutorials , game tutorials, scriblings etc from dream in code.net. all the programming tutorials contents can be accessed by tap.... Requirements: Windows...
1024 KB  
Education  -  Hello Code 1.2.0.0
This application shows you the popular "Hello World" code line of 50 programming languages. Requirements: Windows Phone 8.1, Windows Phone 8, Windows Phone 7.5
1024 KB  
Development Editors  -  UltraGram 5.0 B60
UltraGram is an advanced visual parser generator that provides functionality for creating grammar of a parser, interpreter or compiler, extensively test it and generate parser source code in a preferred programming language. Main advantages of...
3.6 MB  
Libraries  -  Stunnix VBscript and ASP Obfuscator 4.6
Stunnix ASP and VbScript Obfuscator is a unique solution for this piracy and misuse problem for ASP and client-side code written in VBScript programming languages. It provides both an obfuscation and an encoding tool for client-side VBScript code...
 
Programming  -  CLIG 1.2.0
CLIG - Command Line Interface Generator Clig is a code generator for several programming languages that allows you easy creation of command line parsers. Including a GUI and Command Line tool.
34.95 KB  
Programming  -  devkitPro 1.5.7
This project is for homebrew console development tools based on the gnu compiler collection with additional tools and libraries to aid programming each supported console. The windows variants are built with MinGW.
444.26 KB  
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
Programming  -  FLEX-db Digital Asset Manager 3.0.9
FLEX-db - an enterprise Digital Asset Manager (DAM). It ingests and links metadata with files, creates thumbnails, and processes files using business rules. FLEX-db has a JSP client, Java app server for file input and output and an EJB metadata...
21.57 MB  
Programming  -  Libicom 0.9.0
The libicom library is a character based dynamicly linked library for Linux. It is used to remotely control the Icom IC-R8500 wide band receiver via an RS232 link. All call and return parameters to the control functions are character string based....
20.48 KB  
Programming  -  dotdesktop 0.3
Dotdesktop library provides ability to parse desktop entry file and access the information in a convenient way. Desktop entry file format is defined by freedesktop.org, it is used to describe information about an application such as the name and...
327.68 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  libyasl 0.2
Libyasl is a C++ class library to easily realize TCP/UDP/Multicast clientsand servers in IPv4 and IPv6 environments under GNU/Linux systems.
143.36 KB  
Libraries  -  wolfSSL 3.12.0
The wolfSSL embedded SSL/TLS library is a lightweight SSL library written in ANSI standard C and targeted for embedded and RTOS environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating...
2.73 MB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB