Re: [racket-users] Detect version of OS X

2016-02-24 Thread Norman Gray


Jens Axel, hello.

On 24 Feb 2016, at 14:04, Jens Axel Søgaard wrote:


What happens if  /Library/Tex/texbin is present - but not in the path?


A good point.

Using Matthew's reminder of the existence of find-executable-path (which 
I've used before, but was too focused on "system" here), how about:


#lang racket/base

(require racket/string)

(let ([p (string-join `("/Library/TeX/texbin"
"/usr/texbin"
;; ...plus anywhere else I can think of...
,(getenv "PATH"))
  ":")])
  (parameterize ([current-environment-variables
  (make-environment-variables #"PATH" 
(string->bytes/utf-8 p))])

(let-values ([(base name must-be-dir?)
  (split-path
   (find-executable-path "tex"))])
  (printf "binaries in ~a~%" base

That encodes some platform-specific knowledge in the list of possible 
binary locations, but it can be extended to 'everywhere I've ever heard 
of a LaTeX binary ending up, on any platform, plus some extra 
heuristics', and still be fairly robust.


All the best,

Norman


--
Norman Gray  :  https://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Detect version of OS X

2016-02-24 Thread Jens Axel Søgaard
What happens if  /Library/Tex/texbin is present - but not in the path?

/Jens Axel


2016-02-24 14:34 GMT+01:00 Stephen De Gabrielle :

> Thank you - very good advice - I'll have to change my pull request.
> S.
>
> On Wed, 24 Feb 2016 at 10:57, Norman Gray  wrote:
>
>>
>> Greetings
>>
>> On 23 Feb 2016, at 20:46, Jens Axel Søgaard wrote:
>>
>> > Use case: The paths to LaTeX has changed on El Capitan,
>> > which makes it difficult to choose a default path, that works
>> > for all.
>>
>> Addressing that particular use-case (following the motto that one should
>> test the functionality rather than switch on the version), and if a
>> system call is OK, then adapting Stephen De Gabrielle's example you
>> could try
>>
>> #lang racket/base
>> (require racket/system racket/port)
>>
>> (let-values (((base name must-be-dir?)
>>(split-path
>> (string->path
>>  (with-output-to-string (λ ()
>>   (system "which tex")))
>>(printf "binaries in ~a~%" base))
>>
>> or call out to "tlmgr conf" or one of its subcommands (if your
>> installation is based on TeXLive).  This would obviously work on other
>> unixes, and there might be a path-searching equivalent on Windows, too.
>>
>> All the best,
>>
>> Norman
>>
>>
>> --
>> Norman Gray  :  https://nxg.me.uk
>> SUPA School of Physics and Astronomy, University of Glasgow, UK
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>


-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Detect version of OS X

2016-02-24 Thread Matthew Flatt
I recommend `find-executable-path` instead of `system` plus "which".

At Wed, 24 Feb 2016 13:34:19 +, Stephen De Gabrielle wrote:
> Thank you - very good advice - I'll have to change my pull request.
> S.
> On Wed, 24 Feb 2016 at 10:57, Norman Gray  wrote:
> 
> >
> > Greetings
> >
> > On 23 Feb 2016, at 20:46, Jens Axel Søgaard wrote:
> >
> > > Use case: The paths to LaTeX has changed on El Capitan,
> > > which makes it difficult to choose a default path, that works
> > > for all.
> >
> > Addressing that particular use-case (following the motto that one should
> > test the functionality rather than switch on the version), and if a
> > system call is OK, then adapting Stephen De Gabrielle's example you
> > could try
> >
> > #lang racket/base
> > (require racket/system racket/port)
> >
> > (let-values (((base name must-be-dir?)
> >(split-path
> > (string->path
> >  (with-output-to-string (λ ()
> >   (system "which tex")))
> >(printf "binaries in ~a~%" base))
> >
> > or call out to "tlmgr conf" or one of its subcommands (if your
> > installation is based on TeXLive).  This would obviously work on other
> > unixes, and there might be a path-searching equivalent on Windows, too.
> >
> > All the best,
> >
> > Norman
> >
> >
> > --
> > Norman Gray  :  https://nxg.me.uk
> > SUPA School of Physics and Astronomy, University of Glasgow, UK
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Detect version of OS X

2016-02-24 Thread Stephen De Gabrielle
Thank you - very good advice - I'll have to change my pull request.
S.
On Wed, 24 Feb 2016 at 10:57, Norman Gray  wrote:

>
> Greetings
>
> On 23 Feb 2016, at 20:46, Jens Axel Søgaard wrote:
>
> > Use case: The paths to LaTeX has changed on El Capitan,
> > which makes it difficult to choose a default path, that works
> > for all.
>
> Addressing that particular use-case (following the motto that one should
> test the functionality rather than switch on the version), and if a
> system call is OK, then adapting Stephen De Gabrielle's example you
> could try
>
> #lang racket/base
> (require racket/system racket/port)
>
> (let-values (((base name must-be-dir?)
>(split-path
> (string->path
>  (with-output-to-string (λ ()
>   (system "which tex")))
>(printf "binaries in ~a~%" base))
>
> or call out to "tlmgr conf" or one of its subcommands (if your
> installation is based on TeXLive).  This would obviously work on other
> unixes, and there might be a path-searching equivalent on Windows, too.
>
> All the best,
>
> Norman
>
>
> --
> Norman Gray  :  https://nxg.me.uk
> SUPA School of Physics and Astronomy, University of Glasgow, UK
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Detect version of OS X

2016-02-24 Thread Norman Gray


Greetings

On 23 Feb 2016, at 20:46, Jens Axel Søgaard wrote:


Use case: The paths to LaTeX has changed on El Capitan,
which makes it difficult to choose a default path, that works
for all.


Addressing that particular use-case (following the motto that one should 
test the functionality rather than switch on the version), and if a 
system call is OK, then adapting Stephen De Gabrielle's example you 
could try


#lang racket/base
(require racket/system racket/port)

(let-values (((base name must-be-dir?)
  (split-path
   (string->path
(with-output-to-string (λ ()
 (system "which tex")))
  (printf "binaries in ~a~%" base))

or call out to "tlmgr conf" or one of its subcommands (if your 
installation is based on TeXLive).  This would obviously work on other 
unixes, and there might be a path-searching equivalent on Windows, too.


All the best,

Norman


--
Norman Gray  :  https://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Detect version of OS X

2016-02-23 Thread Stephen De Gabrielle
what about this?

#lang racket/base
(require racket/system
 racket/port)

(substring (with-output-to-string (lambda () (system "sw_vers
-productVersion"))) 3 5)

I get "10" or "11" respectively, and I believe it will run on older
versions OS X.

s.



On Tue, Feb 23, 2016 at 9:38 PM Jens Axel Søgaard 
wrote:

> The system-type approach looks like this (it ignores the optional third
> version counter):
>
> (match (regexp-match #px".*Kernel Version ([\\d]+[.][\\d]+).*"
> (system-type 'machine))
>   [(list _ version-str) (string->number version-str)]
>   [_ #f])
>
> The expression returns 15.0 on my machine.
>
> The AppKit approach seems to be less likely to break over time?
>
> /Jens Axel
>
>
>
> 2016-02-23 22:23 GMT+01:00 Matthew Flatt :
>
>> You could parse the result of `(system-type 'machine)`, but you might
>> just as well use a little `ffi/unsafe` binding to get
>> `NSAppKitVersionNumber`:
>>
>>  #lang racket/base
>>  (require ffi/unsafe)
>>
>>  (define appkit
>>(ffi-lib "/System/Library/Frameworks/AppKit.framework/AppKit"))
>>  (define NSAppKitVersionNumber
>>(and appkit (get-ffi-obj 'NSAppKitVersionNumber appkit _double)))
>>
>>  (define (version-10.11-or-later?)
>>(NSAppKitVersionNumber . >= . 1389))
>>
>>
>> At Tue, 23 Feb 2016 21:46:55 +0100, Jens Axel Søgaard wrote:
>> > Hi All,
>> >
>> > The function system-type can be used to detect the system type.
>> > Is there a function that returns the version of the operating system?
>> >
>> > Use case: The paths to LaTeX has changed on El Capitan,
>> > which makes it difficult to choose a default path, that works
>> > for all.
>> >
>> > /Jens Axel
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Racket Users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an
>> > email to racket-users+unsubscr...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> --
> Jens Axel Søgaard
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Detect version of OS X

2016-02-23 Thread Jens Axel Søgaard
The system-type approach looks like this (it ignores the optional third
version counter):

(match (regexp-match #px".*Kernel Version ([\\d]+[.][\\d]+).*"
(system-type 'machine))
  [(list _ version-str) (string->number version-str)]
  [_ #f])

The expression returns 15.0 on my machine.

The AppKit approach seems to be less likely to break over time?

/Jens Axel



2016-02-23 22:23 GMT+01:00 Matthew Flatt :

> You could parse the result of `(system-type 'machine)`, but you might
> just as well use a little `ffi/unsafe` binding to get
> `NSAppKitVersionNumber`:
>
>  #lang racket/base
>  (require ffi/unsafe)
>
>  (define appkit
>(ffi-lib "/System/Library/Frameworks/AppKit.framework/AppKit"))
>  (define NSAppKitVersionNumber
>(and appkit (get-ffi-obj 'NSAppKitVersionNumber appkit _double)))
>
>  (define (version-10.11-or-later?)
>(NSAppKitVersionNumber . >= . 1389))
>
>
> At Tue, 23 Feb 2016 21:46:55 +0100, Jens Axel Søgaard wrote:
> > Hi All,
> >
> > The function system-type can be used to detect the system type.
> > Is there a function that returns the version of the operating system?
> >
> > Use case: The paths to LaTeX has changed on El Capitan,
> > which makes it difficult to choose a default path, that works
> > for all.
> >
> > /Jens Axel
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Detect version of OS X

2016-02-23 Thread Matthew Flatt
You could parse the result of `(system-type 'machine)`, but you might
just as well use a little `ffi/unsafe` binding to get
`NSAppKitVersionNumber`:

 #lang racket/base
 (require ffi/unsafe)

 (define appkit
   (ffi-lib "/System/Library/Frameworks/AppKit.framework/AppKit"))
 (define NSAppKitVersionNumber
   (and appkit (get-ffi-obj 'NSAppKitVersionNumber appkit _double)))

 (define (version-10.11-or-later?)
   (NSAppKitVersionNumber . >= . 1389))


At Tue, 23 Feb 2016 21:46:55 +0100, Jens Axel Søgaard wrote:
> Hi All,
> 
> The function system-type can be used to detect the system type.
> Is there a function that returns the version of the operating system?
> 
> Use case: The paths to LaTeX has changed on El Capitan,
> which makes it difficult to choose a default path, that works
> for all.
> 
> /Jens Axel
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.