Skip to content

Instantly share code, notes, and snippets.


Ivar Nesje ivarne

  • Oslo, Norway
View GitHub Profile
View generate_widget_include.js
const fs = require("fs");
const path = require("path");
const asset_manifest = JSON.parse(
fs.readFileSync("./build/asset-manifest.json", { encoding: "utf8" })
const startupScript = fs.readFileSync(
path.join("./build", asset_manifest["runtime~main.js"])
View Backporting

Backporting policy

Becasue Julia is in rapid development and we need the freedom to to backwards incompatible changes on the master branch, the Julia community has decided that we want to do regular releases for people who wants a more stable enviroment to get the Julia experience. As bugs are discovered in the released versions, we will make a best effort attempt to fix them and release bugfix releases. We call this process backporting because usually it involves cherry-picking commits from the master branch onto the release branch.

Backwards Compatibility

  1. The fundamental rule for compatibility is that a program that doesn't rely on something we consider a bug (eg. exceptions and wrong method results), that works on 0.3.x must work without modification on 0.3.y where y > x.

Forwards compatibility

View 15_digits.jl
num = rand(1_000_000)
len = map(rand(1_000_000)) do a
e = string(a)
if e[1] == '0'
h = hist(len)
View REPLCompletions.diff
diff --git a/base/REPLCompletions.jl b/base/REPLCompletions.jl
index df8c965..d9a8a2c 100644
--- a/base/REPLCompletions.jl
+++ b/base/REPLCompletions.jl
@@ -183,6 +183,17 @@ function latex_completions(string, pos)
function completions(string, pos)
+ try
View interfaces.jl
const _interfaces = Dict{Function,Vector{DataType}}()
function addInterface(d::DataType, f::Function...)
for g in f
if haskey(_interfaces, g)
push!(_interfaces[g], d)
_interfaces[g] = DataType[d]
View testsums.jl
module testsums
export sum5, sum5b, dosums
function sum5(scale, sa1, a1, sa2, a2, sa3, a3, sa4, a4, sa5, a5, out)
for i=1:length(out)
@inbounds out[i] = scale*(sa1*a1[i] + sa2*a2[i] + sa3*a3[i]
+ sa4*a4[i] + sa5*a5[i])
View Compiller warnings openlibm
src/e_j0.c:281:10: warning: variable 'p' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
else if(ix>=0x40000000){p = pR2; q= pS2;}
src/e_j0.c:283:6: note: uninitialized use occurs here
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
src/e_j0.c:281:7: note: remove the 'if' if its condition is always true
else if(ix>=0x40000000){p = pR2; q= pS2;}
src/e_j0.c:273:17: note: initialize the variable 'p' to silence this warning

Dealing with errno in c-APIs in Julia

Lots of C APIs that you might want to call from julia uses a special thread local global integer errno to indicate errors because C only allows one return value and does not provide exceptions to indicate errors. Usually the function interface will define a special return value to indicate an error, and let set errno to a number that represents an index into an array of standard error messages. Some functions, like unix strtoul, do not have a special value to indicate error, but says it will change errno to an appropriate value if an error is encountered. This will require a cautious programmer to set errno = 0; before calling the function and check if it is different from 0 after calling the function.

Example usage in c

errno = 0;
arg = strtoul (buf, NULL, 0);
if (errno)
    perror ("strtoul");
gfortran -o $2 -fno-underscoring $1 libhgraph.a -L/usr/X11R6/lib64 -lX11
View test_colon.jl
function old_colon{T<:Integer}(start::T, step::T, stop::T)
Range(start, step, max(0, div(stop-start+step, step)))
function new_colon{T<:Integer}(start::T, step::T, stop::T)
len,rem = divrem(stop-start,step)
Range(start, step, max(0, len+div(rem+step,step)))
function range_test_old()