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

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

Serving Software Downloads in 956 Categories, Downloaded 50.332.768 Times

Perl6::Currying 0.05

  Date Added: October 08, 2010  |  Visits: 882

Perl6::Currying

Report Broken Link
Printer Friendly Version


Product Homepage
Download (89 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
USER REVIEWS
More Reviews or Write Review


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  
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  
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  
Programming  -  Html2perl 0.2
Html2perl is a simple console based utility for converting HTML text streams (or any ASCII based text stream for that matter) into a series of perl print statements for inclusion in a Perl script.
36.54 KB  
Programming  -  SpecTcl 1.0
SpecTcl is a WYSIWYG GUI-Builder for Tcl/Tk, with sibblings for generating code in Perl, Java, Python & Ruby. It runs on all platforms where Tcl/Tk runs. It is simple and quick to use, yet still powerful when you know your Tcl/Tk.
2.08 MB  
Development Tools  -  UIZE JavaScript API 1.0
UIZE JavaScript API is a suite of code libraries to help you create more effective user interfaces in your Web content and Web-based applications and services. The UIZE JavaScript API has been designed making full use of the object orientation...
 
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
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  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB  
Libraries  -  wolfSSL 4.0.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...
3.88 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