SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
The Qore Language
... for the Perl programmer
B. Estrade
http://houston.pm.org/
September 8th, 2011
What is Qore?
According to Qore.org:
"...
●thread-capable,
●embeddable,
●weakly-typed
●optionally strongly typed
●procedural
●object-oriented
..."
Qore's Influences
According to http://en.wikipedia.org/wiki/Qore_Language:
But, docs mention:
●Perl
●D
●Java
●C++
Some of Qore's Primary Design Goals
●natively multi-threaded, so scalable on SMP architectures
●embeddable
●native object serialization (JSON, XML)
●native database support (MySQL, Oracle, etc)
Never heard of Qore? Neither had I.
●used to do a lot of simulations of parallel things
with Perl, serially
●wanted to use real threads to model threading, but "knew"
Perl's threading options sucked
●So, I searched for a while and found Qore
●I liked it so much, I created a FreeBSD port for it
- http://www.freshports.org/lang/qore/
What's to like about Qore?
●Familiarity
○it's eerily similar to Perl in many ways - data structures,
operators, sigils, subroutines, TIMTOWTDI (usually), etc
●Allows Freeflow of thought
○The language syntax and semantics stay mostly out of the
way of thought and expression, much like Perl
●It's meant to be threaded
●Imagine if Perl was designed from the beginning to support
threads.
The Reality
●Qore is not nearly as expressive as Perl
●Not as "DWIM" as Perl
●Threading support could be at a higher level
●No real community (like none), so no C"Q"AN
●Still very cool and not a toy
Scripting's Role in the Many-Core Era
●scripting languages will be exposed as handicapped if they
can't make native use of many-core
●most scripting languages are terrible at this
●I believe that interpreted offer the greatest opportunity for
intuitive interfaces to many-core; as opposed to:
○ compiler/directive support (e.g., OpenMP)
○ low level threading libraries (e.g., PThreads, Portable Coroutine Library)
○ low level communication libraries (MPI)
● Don't get me wrong, I still <3 OpenMP & PCL :)
State of Threads Many-Core in Perl?
●It's not just about threads, it's about taking advantage of
many-core environments in as many Perlish ways as
possible.
● Some options:
○ Coro, AnyEvent
○ ExtUtils-nvcc, CUDA::Minimal, Perl OpenGL
○ PDL::Parallel::MPI, Parallel::MPI::Simple
○ ..?
● Wishful Options:
○ Parallel::OpenMP
○ Perl OpenCL
○ Inline::Qore
○ ..?
Where to get Qore?
●http://www.qore.org (latest, 0.8.2)
●MacPorts (0.8.2)
●lang/qore in FreeBSD Ports (mine, @0.8.0)
"Core" Qore, Under the Hood
●Bison
○parser generator (like Yacc)
●Flex
○lexical scanner, tokenizer
●pcre
○Perl compatible regular expression library
●libxml2
●supported modules require other libaries
Qore has Optional Data Typing
●boolean
●string
●int (64 bit, signed)
●float (double)
●date
●binary blob (opaque)
●NULL - a state of undefinedness, like undef;
●NOTHING - no value, like the empty string, q{};
NULL != NOTHING;
NULL really is something;
NOTHING really is nothing.
The World says, Hello.
#!qore
%enable-all-warnings
print("Hello!n");
#!perl
use strict;
use warnings;
print("Hello!n");
Data Containers
#!qore
%enable-all-warnings
# scalars
my $x = 1;
# arrays
my $list=(1,2,'three',4.0,2001-01-15Z);
# hashes
my $hash=("a":1, "b":'two',"c":2.4);
#!perl
use strict;
use warnings;
# scalars
my $x = 1;
# arrays
my @list=(1,2,'three',4.0,'2001-01-15Z');
# hashes
my %hash = ("a"=>1, "b"=>two',"c"=>2.4);
Data Container Iteration
#!qore
%enable-all-warnings
# scalars
my $x = 0;
printf("%sn",$x);
# arrays
my $list=(1,2,'three',4.0,2001-01-15Z);
foreach my $i in ($list) {
printf("%sn",$i);
}
# hashes
my $hash=("a":1, "b":'two',"c":2.4);
foreach my $k in (keys $hash) {
printf("%s = %sn",$k,$hash.$k);
}
#!perl
use strict;
use warnings;
# scalar
my $x = 0;
printf("%sn",$x);
#arrays
my @list=(1,2,'three',4.0,'2001-01-15Z');
foreach my $i (@list) {
printf("%sn",$i);
}
# hashes
my %hash = ("a"=>1, "b"=>'two',"c"=>2.4);
foreach my $k (keys %hash) {
printf("%s = %sn",$k,$hash{$k});
}
Complex Data Structures
#!qore
%enable-all-warnings
# arrays of arrays
my $list=((1,2,3),
(4,5,6),
(7,8,9));
# hash of arrays
my $hash=('a':(1,2,3),
'b':(4,5,6),
'c':(7,8,9));
#!perl
use strict;
use warnings;
# arrays of arrays
my @list=([1,2,3],
[4,5,6],
[7,8,9]);
# hash of arrays
my %hash=('a'=>[1,2,3],
'b'=>[4,5,6],
'c'=>[7,8,9]);
Some Qore Array and Hash Operators
Arrays:
●shift, unshift
●pop, push
●splice
●map, foldl, foldr
●elements (counts)
Hashes
●keys (insert/creation order)
●delete (clear value)
●remove (remove from hash)
●elements
●find (query contents of hash on key and value)
Regular Expressions - whoa...
#!qore
%enable-all-warnings
my $t = 'Branches'; # text
my $s = 'abc'; # string
my $p = 'a|z'; # pattern
printf("%s %s: "'%s' =~ /%s/"n", ( $s =~ /a|z/ ) ? 'PASS' : 'FAIL' ,$t, $s, $p);
$s = 'qrs';
printf("%s %s: "'%s' !~ /%s/"n", ( $s !~ /a|z/ ) ? 'PASS' : 'FAIL' ,$t, $s, $p);
#!perl
use strict;
use warnings;
my $t = 'Branches'; # text
my $s = 'abc'; # string
my $p = 'a|z'; # pattern
printf("%s %s: "'%s' =~ /%s/"n", ( $s =~ /a|z/ ) ? 'PASS' : 'FAIL' ,$t, $s, $p);
$s = 'qrs';
printf("%s %s: "'%s' !~ /%s/"n", ( $s !~ /a|z/ ) ? 'PASS' : 'FAIL' ,$t, $s, $p);
... code is valid in both Perl and Qore!
Subroutines & Closures
#!qore
%enable-all-warnings
# defined sub
sub say_hello (string $name) {
printf("Hello, %s!n",$name);
}
# call sub
say_hello("Frank");
# anonymous sub via closure
my code $anonymous_sub =
sub (string $name) {
printf("Hello, %s!n",$name);
};
$anonymous_sub("Frank");
#!perl
use strict;
use warnings;
# defined sub
sub say_hello {
my $name = shift;
printf("Hello, %s!n",$name);
}
# call sub
say_hello("Frank");
# anonymous sub via closure
my $anonymous_sub =
sub {
my $name = shift;
printf("Hello, %s!n",$name);
};
$anonymous_sub->("Frank");
Qore Subroutes & Closures
● General form is one of 2:
[return_type] sub func_name([[type] variable,..]) {
... code block
}
OR
sub func_name([[type] variable,..]) [returns return_type] {
... code block
}
● Subroutines and closures also provide event handlers (inspired by D):
○ on_exit
○ on_success
○ on_exit
sub myfunc() {
on_exit do_x(); #subroutine called on exit, unconditionally
... code block;
return ..something;
}
Classes in Qore (w/o Perl counter example :(
%require-our
%enable-all-warnings
class MyClass {
# declare some private members
private $.base1, $.x;
constructor($a) {
printf("Base1::constructor(%n)n", $a);
$.a = $a;
}
destructor() {
printf("Base1::destructor() (%n)n", $.a);
}
copy() {
printf("Base1::copy() (%n)n", $.a);
$.a = $.a + "-copy";
}
hello() {
printf("Base1 hello (%n, derived class %n)n", $.a, cast<Mid>($self).subclass());
}
}
Qore Threading...finally
●invoked with background keyword
●%require-our to declare shares globals with "our"
○useful for implicit communication via shared memory
●use "my" to specify thread-local variables
●synchronization
○locks
○gates (recursive locks)
○conditional block
○mutex
●communication
○thread safe Queue class
The World says, Hello_r.
#!qore
%require-our
%enable-all-warnings
#shared, thread safe
our $tcount = new Counter();
sub say_hello_r () {
on_exit $tcount.dec();
my $tid = gettid();
printf("Hello! from Thread %sn",$tid);
}
for (my $i = 0; $i < 9; $i++) {
$tcount.inc();
background say_hello_r();
}
$tcount.waitForZero();
$qore ./hello_r.q
Hello! from Thread 2
Hello! from Thread 3
Hello! from Thread 4
Hello! from Thread 7
Hello! from Thread 6
Hello! from Thread 10
Hello! from Thread 5
Hello! from Thread 9
Hello! from Thread 8
Hello! from Thread 11
●higher level constructs, similar in spirit to OpenMP (fork/join),
e.g.:
●better data environment control (private,shared,etc)
●process affinity control
●memory allocation/migration control (first touch, next touch)
●logical affine "locations"
My Thread Support Wish List
our $count = 0;
background {
critical {
$count++;
};
};
A lot more to Qore
●modules for database, XML, JSON
●interesting operators and idioms
●embeddable
●plenty of warts and room for improvement
○lacks syntactical sweetness of Perl
○higher level threading features
○needs more DWIM
Possible Future Talks, Discussions
●Perl's threading and asynchronous options (not me:)
●More on Qore's threading
●How to embed Qore (a design goal)
●Qore for web apps (design goal)
●Using Qore for threading in Perl - Inline::Qore, anyone?
●'Perqore' challenge, Polyglot programming with Perl & Qore
●Cray's Chapel Language - not as Perlish as Qore
●Lua - threading and coroutines
●Any D fans?
Qore Resources
http://www.qore.org
●core language documention
●module documention
●C++ API Doxygen docs (for embedding & internals)

Mais conteúdo relacionado

Mais procurados

Groovy on the Shell
Groovy on the ShellGroovy on the Shell
Groovy on the Shellsascha_klein
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0Tim Bunce
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet
 
NativeBoost
NativeBoostNativeBoost
NativeBoostESUG
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machinejulien pauli
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTSjulien pauli
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from insidejulien pauli
 
Rust tutorial from Boston Meetup 2015-07-22
Rust tutorial from Boston Meetup 2015-07-22Rust tutorial from Boston Meetup 2015-07-22
Rust tutorial from Boston Meetup 2015-07-22nikomatsakis
 

Mais procurados (20)

Groovy on the Shell
Groovy on the ShellGroovy on the Shell
Groovy on the Shell
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0PL/Perl - New Features in PostgreSQL 9.0
PL/Perl - New Features in PostgreSQL 9.0
 
Php engine
Php enginePhp engine
Php engine
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Python for Penetration testers
Python for Penetration testersPython for Penetration testers
Python for Penetration testers
 
Unix - Shell Scripts
Unix - Shell ScriptsUnix - Shell Scripts
Unix - Shell Scripts
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
NativeBoost
NativeBoostNativeBoost
NativeBoost
 
Introduction to Rust
Introduction to RustIntroduction to Rust
Introduction to Rust
 
Rust言語紹介
Rust言語紹介Rust言語紹介
Rust言語紹介
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machine
 
Unix shell scripting
Unix shell scriptingUnix shell scripting
Unix shell scripting
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTS
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
Shell Script
Shell ScriptShell Script
Shell Script
 
Rust tutorial from Boston Meetup 2015-07-22
Rust tutorial from Boston Meetup 2015-07-22Rust tutorial from Boston Meetup 2015-07-22
Rust tutorial from Boston Meetup 2015-07-22
 

Semelhante a Qore for the Perl Programmer

Semelhante a Qore for the Perl Programmer (20)

Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Bioinformatica p4-io
Bioinformatica p4-ioBioinformatica p4-io
Bioinformatica p4-io
 
Easy native wrappers with SWIG
Easy native wrappers with SWIGEasy native wrappers with SWIG
Easy native wrappers with SWIG
 
javascript teach
javascript teachjavascript teach
javascript teach
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
 
Node.js for Rubists
Node.js for RubistsNode.js for Rubists
Node.js for Rubists
 
Perl at SkyCon'12
Perl at SkyCon'12Perl at SkyCon'12
Perl at SkyCon'12
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 

Último

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 

Último (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 

Qore for the Perl Programmer

  • 1. The Qore Language ... for the Perl programmer B. Estrade http://houston.pm.org/ September 8th, 2011
  • 2. What is Qore? According to Qore.org: "... ●thread-capable, ●embeddable, ●weakly-typed ●optionally strongly typed ●procedural ●object-oriented ..."
  • 3. Qore's Influences According to http://en.wikipedia.org/wiki/Qore_Language: But, docs mention: ●Perl ●D ●Java ●C++
  • 4. Some of Qore's Primary Design Goals ●natively multi-threaded, so scalable on SMP architectures ●embeddable ●native object serialization (JSON, XML) ●native database support (MySQL, Oracle, etc)
  • 5. Never heard of Qore? Neither had I. ●used to do a lot of simulations of parallel things with Perl, serially ●wanted to use real threads to model threading, but "knew" Perl's threading options sucked ●So, I searched for a while and found Qore ●I liked it so much, I created a FreeBSD port for it - http://www.freshports.org/lang/qore/
  • 6. What's to like about Qore? ●Familiarity ○it's eerily similar to Perl in many ways - data structures, operators, sigils, subroutines, TIMTOWTDI (usually), etc ●Allows Freeflow of thought ○The language syntax and semantics stay mostly out of the way of thought and expression, much like Perl ●It's meant to be threaded ●Imagine if Perl was designed from the beginning to support threads.
  • 7. The Reality ●Qore is not nearly as expressive as Perl ●Not as "DWIM" as Perl ●Threading support could be at a higher level ●No real community (like none), so no C"Q"AN ●Still very cool and not a toy
  • 8. Scripting's Role in the Many-Core Era ●scripting languages will be exposed as handicapped if they can't make native use of many-core ●most scripting languages are terrible at this ●I believe that interpreted offer the greatest opportunity for intuitive interfaces to many-core; as opposed to: ○ compiler/directive support (e.g., OpenMP) ○ low level threading libraries (e.g., PThreads, Portable Coroutine Library) ○ low level communication libraries (MPI) ● Don't get me wrong, I still <3 OpenMP & PCL :)
  • 9. State of Threads Many-Core in Perl? ●It's not just about threads, it's about taking advantage of many-core environments in as many Perlish ways as possible. ● Some options: ○ Coro, AnyEvent ○ ExtUtils-nvcc, CUDA::Minimal, Perl OpenGL ○ PDL::Parallel::MPI, Parallel::MPI::Simple ○ ..? ● Wishful Options: ○ Parallel::OpenMP ○ Perl OpenCL ○ Inline::Qore ○ ..?
  • 10. Where to get Qore? ●http://www.qore.org (latest, 0.8.2) ●MacPorts (0.8.2) ●lang/qore in FreeBSD Ports (mine, @0.8.0)
  • 11. "Core" Qore, Under the Hood ●Bison ○parser generator (like Yacc) ●Flex ○lexical scanner, tokenizer ●pcre ○Perl compatible regular expression library ●libxml2 ●supported modules require other libaries
  • 12. Qore has Optional Data Typing ●boolean ●string ●int (64 bit, signed) ●float (double) ●date ●binary blob (opaque) ●NULL - a state of undefinedness, like undef; ●NOTHING - no value, like the empty string, q{}; NULL != NOTHING; NULL really is something; NOTHING really is nothing.
  • 13. The World says, Hello. #!qore %enable-all-warnings print("Hello!n"); #!perl use strict; use warnings; print("Hello!n");
  • 14. Data Containers #!qore %enable-all-warnings # scalars my $x = 1; # arrays my $list=(1,2,'three',4.0,2001-01-15Z); # hashes my $hash=("a":1, "b":'two',"c":2.4); #!perl use strict; use warnings; # scalars my $x = 1; # arrays my @list=(1,2,'three',4.0,'2001-01-15Z'); # hashes my %hash = ("a"=>1, "b"=>two',"c"=>2.4);
  • 15. Data Container Iteration #!qore %enable-all-warnings # scalars my $x = 0; printf("%sn",$x); # arrays my $list=(1,2,'three',4.0,2001-01-15Z); foreach my $i in ($list) { printf("%sn",$i); } # hashes my $hash=("a":1, "b":'two',"c":2.4); foreach my $k in (keys $hash) { printf("%s = %sn",$k,$hash.$k); } #!perl use strict; use warnings; # scalar my $x = 0; printf("%sn",$x); #arrays my @list=(1,2,'three',4.0,'2001-01-15Z'); foreach my $i (@list) { printf("%sn",$i); } # hashes my %hash = ("a"=>1, "b"=>'two',"c"=>2.4); foreach my $k (keys %hash) { printf("%s = %sn",$k,$hash{$k}); }
  • 16. Complex Data Structures #!qore %enable-all-warnings # arrays of arrays my $list=((1,2,3), (4,5,6), (7,8,9)); # hash of arrays my $hash=('a':(1,2,3), 'b':(4,5,6), 'c':(7,8,9)); #!perl use strict; use warnings; # arrays of arrays my @list=([1,2,3], [4,5,6], [7,8,9]); # hash of arrays my %hash=('a'=>[1,2,3], 'b'=>[4,5,6], 'c'=>[7,8,9]);
  • 17. Some Qore Array and Hash Operators Arrays: ●shift, unshift ●pop, push ●splice ●map, foldl, foldr ●elements (counts) Hashes ●keys (insert/creation order) ●delete (clear value) ●remove (remove from hash) ●elements ●find (query contents of hash on key and value)
  • 18. Regular Expressions - whoa... #!qore %enable-all-warnings my $t = 'Branches'; # text my $s = 'abc'; # string my $p = 'a|z'; # pattern printf("%s %s: "'%s' =~ /%s/"n", ( $s =~ /a|z/ ) ? 'PASS' : 'FAIL' ,$t, $s, $p); $s = 'qrs'; printf("%s %s: "'%s' !~ /%s/"n", ( $s !~ /a|z/ ) ? 'PASS' : 'FAIL' ,$t, $s, $p); #!perl use strict; use warnings; my $t = 'Branches'; # text my $s = 'abc'; # string my $p = 'a|z'; # pattern printf("%s %s: "'%s' =~ /%s/"n", ( $s =~ /a|z/ ) ? 'PASS' : 'FAIL' ,$t, $s, $p); $s = 'qrs'; printf("%s %s: "'%s' !~ /%s/"n", ( $s !~ /a|z/ ) ? 'PASS' : 'FAIL' ,$t, $s, $p); ... code is valid in both Perl and Qore!
  • 19. Subroutines & Closures #!qore %enable-all-warnings # defined sub sub say_hello (string $name) { printf("Hello, %s!n",$name); } # call sub say_hello("Frank"); # anonymous sub via closure my code $anonymous_sub = sub (string $name) { printf("Hello, %s!n",$name); }; $anonymous_sub("Frank"); #!perl use strict; use warnings; # defined sub sub say_hello { my $name = shift; printf("Hello, %s!n",$name); } # call sub say_hello("Frank"); # anonymous sub via closure my $anonymous_sub = sub { my $name = shift; printf("Hello, %s!n",$name); }; $anonymous_sub->("Frank");
  • 20. Qore Subroutes & Closures ● General form is one of 2: [return_type] sub func_name([[type] variable,..]) { ... code block } OR sub func_name([[type] variable,..]) [returns return_type] { ... code block } ● Subroutines and closures also provide event handlers (inspired by D): ○ on_exit ○ on_success ○ on_exit sub myfunc() { on_exit do_x(); #subroutine called on exit, unconditionally ... code block; return ..something; }
  • 21. Classes in Qore (w/o Perl counter example :( %require-our %enable-all-warnings class MyClass { # declare some private members private $.base1, $.x; constructor($a) { printf("Base1::constructor(%n)n", $a); $.a = $a; } destructor() { printf("Base1::destructor() (%n)n", $.a); } copy() { printf("Base1::copy() (%n)n", $.a); $.a = $.a + "-copy"; } hello() { printf("Base1 hello (%n, derived class %n)n", $.a, cast<Mid>($self).subclass()); } }
  • 22. Qore Threading...finally ●invoked with background keyword ●%require-our to declare shares globals with "our" ○useful for implicit communication via shared memory ●use "my" to specify thread-local variables ●synchronization ○locks ○gates (recursive locks) ○conditional block ○mutex ●communication ○thread safe Queue class
  • 23. The World says, Hello_r. #!qore %require-our %enable-all-warnings #shared, thread safe our $tcount = new Counter(); sub say_hello_r () { on_exit $tcount.dec(); my $tid = gettid(); printf("Hello! from Thread %sn",$tid); } for (my $i = 0; $i < 9; $i++) { $tcount.inc(); background say_hello_r(); } $tcount.waitForZero(); $qore ./hello_r.q Hello! from Thread 2 Hello! from Thread 3 Hello! from Thread 4 Hello! from Thread 7 Hello! from Thread 6 Hello! from Thread 10 Hello! from Thread 5 Hello! from Thread 9 Hello! from Thread 8 Hello! from Thread 11
  • 24. ●higher level constructs, similar in spirit to OpenMP (fork/join), e.g.: ●better data environment control (private,shared,etc) ●process affinity control ●memory allocation/migration control (first touch, next touch) ●logical affine "locations" My Thread Support Wish List our $count = 0; background { critical { $count++; }; };
  • 25. A lot more to Qore ●modules for database, XML, JSON ●interesting operators and idioms ●embeddable ●plenty of warts and room for improvement ○lacks syntactical sweetness of Perl ○higher level threading features ○needs more DWIM
  • 26. Possible Future Talks, Discussions ●Perl's threading and asynchronous options (not me:) ●More on Qore's threading ●How to embed Qore (a design goal) ●Qore for web apps (design goal) ●Using Qore for threading in Perl - Inline::Qore, anyone? ●'Perqore' challenge, Polyglot programming with Perl & Qore ●Cray's Chapel Language - not as Perlish as Qore ●Lua - threading and coroutines ●Any D fans?
  • 27. Qore Resources http://www.qore.org ●core language documention ●module documention ●C++ API Doxygen docs (for embedding & internals)