SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
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)

Weitere Àhnliche Inhalte

Was ist angesagt?

Unix - Shell Scripts
Unix - Shell ScriptsUnix - Shell Scripts
Unix - Shell Scripts
ananthimurugesan
 

Was ist angesagt? (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
 

Ähnlich wie Qore for the Perl Programmer

javascript teach
javascript teachjavascript teach
javascript teach
guest3732fa
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
guest3732fa
 
Node.js for Rubists
Node.js for RubistsNode.js for Rubists
Node.js for Rubists
Sagiv Ofek
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
oscon2007
 

Ähnlich wie 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
 

KĂŒrzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

KĂŒrzlich hochgeladen (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

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)