码迷,mamicode.com
首页 > 其他好文 > 详细

第一个racket程序:获得字符串中的数字

时间:2014-05-07 03:17:09      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:blog   class   code   ext   get   http   

#! /usr/bin/env racket
#lang racket
#|
  NAME:
     getModelNumber.rkt
     This program is used to get model number based on the
     input model file name.
  USAGE:
     ./getModelNumber.rkt modelfilename
  EXAMPLE:
     ./getModelNumber.rkt gitst22.mat
  OUTPUT:
     22
|#

;; deal with the arguments
(define verbose? (make-parameter #f))
(define fileformat? (make-parameter #f))
(define argslist 
  (command-line
   #:usage-help
   "Get model number based on the filename."
   #:once-each        
   [("-v" "--verbose") "Verbose mode" (verbose? #t)]
   #:args
   (filename [format ".mat"]) (list filename format)))

;; define indicator
(define number -1)
(define filename (list-ref argslist 0))
(define format (list-ref argslist 1))

;; check the filename format is legal.
(if (regexp-match? (string-append format "$") filename)
    (fileformat? #t)
    (when (verbose?)
      (display "Filename must be end format of .mat \n")));

;; get the model number
(define getNumber
  (lambda (filename)
    (regexp-match #px"\\d+" filename)))

(when (and (getNumber filename)
           (fileformat?))
  (set! number
        (string->number (list-ref (getNumber filename) 0))))

number    ; return number value.

运行如下:

bubuko.com,布布扣

第一个racket程序:获得字符串中的数字,布布扣,bubuko.com

第一个racket程序:获得字符串中的数字

标签:blog   class   code   ext   get   http   

原文地址:http://blog.csdn.net/loveaborn/article/details/25037997

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!